How triggers in code are synced to the database and UI
- Source of truth: The
triggers.yamlfile is the source of truth for trigger definitions. - Sync flow: A background scheduler process periodically syncs triggers from
triggers.yamlinto the database. Only triggers that pass the envs filter (see Envs filter) are created or updated on that instance. After a trigger is synced to the database, it appears in the Triggers UI. - New/updates flow both ways: New or updated triggers in the YAML are pushed to the database when the scheduler runs. Edits you make in the UI to a trigger that’s defined in code are written back to
triggers.yamlso UI and code stay in sync. - Deletions are not synced: Removing a trigger from
triggers.yamldoes not remove it from the database. You must delete the trigger in the UI (or via API) to remove it from the database. See Delete triggers.
Create and configure triggers
Here are the steps to create and configure triggers via code:-
Create a
triggers.yamlfile under your pipeline folder. The file path should bepipelines/[pipeline_uuid]/triggers.yaml. -
Enter your trigger configs into the
triggers.yamlfile.- Content structure
- Required trigger fields
name: Unique identifier of the trigger (per pipeline).schedule_type:timeorapifor new triggers.eventis deprecated and should only be used to maintain existing legacy event triggers.- For time (schedule) triggers:
schedule_intervalandstart_timeare required.schedule_interval:@once,@hourly,@daily,@weekly,@monthly,@always_on, or a Cron expression (e.g.* * * * *).start_time: Persisted schedule start timestamp. For@once, this is the single run time (e.g.2023-01-01or2023-01-01 00:00:00).
- For api triggers:
schedule_intervalandstart_timeare typically not used for execution but may still be present in the config.
- Optional trigger fields
status:activeorinactive. Defaults toinactiveif omitted.variables: A dictionary of runtime variables for this trigger.sla: SLA in seconds for this trigger.settings: A dictionary of advanced settings:skip_if_previous_running:true/false— do not start a new run if the previous run is still in progress.allow_blocks_to_fail:true/false— allow the pipeline to continue running non-dependent blocks if some blocks fail.create_initial_pipeline_run:true/false— create an initial run when the start time is in the past (schedule triggers).
envs: List of environments where this trigger should be synced and run. See Envs filter below.
- Content structure
-
Save the
triggers.yamlfile. On the next scheduler run, trigger configs are synced to the database (subject to the envs filter) and then show in the Triggers UI.- Required trigger fields
name: Unique identifier of the triggerschedule_type:timeorapifor new triggers.eventis deprecated for legacy event triggers only.schedule_interval:@once,@hourly,@daily,@weekly,@monthly,@always_on, or Cron syntax(* * * * *)start_time: Persisted schedule start timestamp. For@once, this is the single run time (e.g.2023-01-01)
- Optional trigger fields
status:activeorinactivevariables: A dictionary of variables that’s associated with the triggersla: SLA in secondssettings: a dictionary of advanced settingsskip_if_previous_running:true/falseallow_blocks_to_fail:true/falsecreate_initial_pipeline_run:true/false
envs: The environments that the trigger runs in.- If
envsis not set or empty, the trigger will run in all environments. - The environment of the Mage app is set via the
ENVenvironment variable. - OSS: Only supports
dev,staging,prod,test. - Mage Pro: Supports any value, which must match the
ENVenvironment variable.
- If
- Required trigger fields
-
Save the
triggers.yamlfile. The trigger configs will be synced to the triggers UI shortly.
Example triggers config:
Envs filter
The optionalenvs field limits which instances or workspaces sync and run the trigger. Each instance/workspace has an environment set by the ENV environment variable.
- When
envsis not set or empty: The trigger is synced to all instances/workspaces. Every environment will get the trigger in the database and can run it. - When
envsis set: The trigger is synced only to instances/workspaces whoseENVvalue is in theenvslist. Other instances will not create or update this trigger in their database, so they will not run it.- OSS: Allowed values are
dev,staging,prod, andtest. - Mage Pro: Any value is allowed; it must match the
ENVset for that instance or workspace.
- OSS: Allowed values are
envs filter to a trigger that already exists everywhere: Triggers that were previously synced (e.g. when envs was empty) remain in the database on instances that no longer match the new envs list. The sync process only creates or updates triggers; it does not delete them. To stop such a trigger from existing (and running) on those instances, you must delete the trigger manually in the UI on each affected instance or workspace.
Modify triggers
If an existing trigger is defined in the YAML file, changes flow both ways: updates in the UI are written back totriggers.yaml, and updates in the YAML are synced to the database (and reflected in the UI when you reload). Only triggers that pass the envs filter are synced to the database on each instance.
Delete triggers
Thetriggers.yaml file is synced into the database automatically, but deletions work differently:
-
Delete one trigger: Removing a trigger from the YAML file does not delete it from the database.
Delete it in the UI on each instance where it exists:
- In the Pipeline triggers table (
/pipelines/[pipeline_uuid]/triggers), click the trash can icon. - In Mage Pro, right-click the trigger row and click Delete.
- In the Pipeline triggers table (
- Delete selected triggers in Mage Pro: On the global Triggers page, select one or more rows on the current page, open Actions, and choose Delete selected (N). Selection applies only to the visible page and does not carry across pagination.
-
Delete matching triggers in Mage Pro: Apply at least one search term or filter on the global
Triggers page, then open Actions and choose Delete matching triggers. This action is
unavailable without a search term or filter. Mage previews the matching count across all pages
and requires you to type
DELETEexactly before deletion. If the set of matching triggers changes after the preview, Mage stops the deletion so you can review the filters again. Triggers outside the current search and filters are not deleted.
triggers.yaml file. Mage marks observed initial and running pipeline-run and
block-run records as cancelled and attempts to stop their executors. Executor cancellation is best
effort, so a worker or a run created concurrently by another scheduler process may continue after the
trigger is deleted. Run and block-run history is preserved, and completed, failed, and
already-cancelled runs are unchanged. After Mage commits the trigger’s inactive state, a cancellation
or final deletion failure leaves the trigger and its YAML definition inactive so you can retry. If an
envs filter previously created the trigger on other instances, delete it manually on
those instances as well; sync does not remove triggers from their databases.
As a reversible alternative, set the trigger’s status to inactive in triggers.yaml. Status
changes are automatically synced to the database and UI.