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:time,api, orevent. Determines how the trigger runs (schedule vs API vs event).- 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: When the schedule starts (e.g.2023-01-01or2023-01-01 00:00:00).
- For api and event 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.
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:
-
Deleting triggers completely:
Removing a trigger from the YAML file does not delete it from the database. You must delete the trigger in the UI on each instance where it exists.
- In the Pipeline triggers table (
/pipeline/[pipeline_uuid]/triggers), click the trash can icon. - In Mage Pro, right-click on the trigger row and click Delete.
triggers.yamlconfig file. If you added an envs filter and the trigger was already created on other instances, delete it manually on those instances as well; sync does not remove triggers from the database. - In the Pipeline triggers table (
-
Alternative to deletion:
Instead of deleting, you can update the trigger status in the YAML file (e.g. set
status: inactive). Status changes are automatically synced to the database and UI.