Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Mage ai Mage ai Destination Emit State

From Leeroopedia


Knowledge Sources
Domains Data_Integration, ETL, State_Management
Last Updated 2026-02-09 00:00 GMT

Overview

Concrete tool for processing and emitting Singer STATE messages on the destination side provided by the Mage integrations Destination base class.

Description

Destination.process_state extracts the state value from a STATE message and calls _emit_state to persist it. _emit_state serializes the state as JSON and writes it to state_file_path (if configured) or to stdout with a flush. In batch mode, __process_batch_set merges bookmarks from multiple accumulated STATE messages before calling process_state once with the merged result.

Usage

Called automatically by _process when STATE messages arrive. Not called directly by subclasses.

Code Reference

Source Location

  • Repository: mage-ai
  • File: mage_integrations/mage_integrations/destinations/base.py
  • Lines: 323-333 (process_state), 598-607 (_emit_state)

Signature

class Destination(ABC):
    def process_state(self, row: Dict, tags: Dict = None) -> None:
        """Process a STATE message.

        Args:
            row: STATE message dict with 'value' key.
            tags: Optional logging tags.
        """

    def _emit_state(self, state: dict) -> None:
        """Write state to file or stdout.

        Args:
            state: State dict to emit.
        """

Import

from mage_integrations.destinations.base import Destination

I/O Contract

Inputs

Name Type Required Description
row Dict Yes STATE message with 'value' key containing bookmarks

Outputs

Name Type Description
state_file_path file State JSON written to file (if configured)
stdout JSON line State JSON written to stdout (if no file path)

Usage Examples

# State is emitted after successful batch export:
# If state_file_path is set:
#   Writes to file: {"bookmarks": {"users": {"updated_at": "2024-01-15"}}}
# Otherwise writes to stdout for capture by orchestrator

# In batch mode, bookmarks from multiple STATE messages are merged:
# STATE 1: {"bookmarks": {"users": {"updated_at": "2024-01-10"}}}
# STATE 2: {"bookmarks": {"users": {"updated_at": "2024-01-15"}}}
# Merged: {"bookmarks": {"users": {"updated_at": "2024-01-15"}}}

Related Pages

Implements Principle

Requires Environment

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment