Deploy and manage triggers
Triggers are deployed with their task, and you can switch them off without deleting them. To pause a nightly job during a data migration, deactivate its trigger and reactivate it afterwards.
Deploying a task with triggers
We recommend that you define your triggers in code together with your tasks and deploy them together.
The Union UI displays:
-
Owner- who last deployed the trigger. -
Last updated- who last activated or deactivated the trigger and when. Note: If you deploy a trigger withauto_activate=True(default), this will match theOwner. -
Last Run- when was the last run created by this trigger.
For development and debugging purposes, you can adjust and deploy individual triggers from the UI.
To deploy a task with its triggers:
flyte.deploy(env)flyte deploy -p <project> -d <domain> <file_with_tasks_and_triggers.py> env
T will be automatically switched to apply to the version of T being deployed, except triggers pinned to a task version, which stay on their pinned version.Triggers on task T that are defined elsewhere, such as in the UI, are deleted unless the task definition of T references them.
Pinning a trigger to a task version
Set task_version on a trigger to keep it on one version of its task while you deploy other versions. A pinned trigger can serve as a stable production entrypoint while CI keeps deploying pre-releases. Requires flyte 2.12.5 or later.
import flyte
env = flyte.TaskEnvironment(name="ingest")
prod = flyte.Trigger(name="prod", automation=flyte.Cron("0 6 * * *"), task_version="v1.4.0")
@env.task(triggers=[prod])
async def entrypoint() -> None:
...When you deploy another version of the task, the pinned trigger keeps launching the pinned version. The rest of the trigger’s definition (automation, inputs, activation, and run settings) is still updated from your code on each deploy. Triggers without task_version keep following each deploy.
To promote or roll back, change task_version and deploy again. The pinned version must already be deployed for the task, or be the version you are deploying. Otherwise the deploy fails.
Activating and deactivating triggers
By default, triggers are automatically activated upon deployment (auto_activate=True).
Alternatively, you can set auto_activate=False to deploy inactive triggers.
An inactive trigger will not create runs until activated.
env = flyte.TaskEnvironment(name="my_task_env")
custom_cron_trigger = flyte.Trigger(
"custom_cron",
flyte.Cron("0 0 * * *"),
auto_activate=False # Dont create runs yet
)
@env.task(triggers=custom_cron_trigger)
def custom_task() -> str:
return "Hello, world!"
This trigger won’t create runs until it is explicitly activated. Activate it, or deactivate a trigger to stop it from creating new runs:
# Activate
flyte.remote.Trigger.update("custom_cron", "my_task_env.custom_task", active=True)
# Deactivate
flyte.remote.Trigger.update("custom_cron", "my_task_env.custom_task", active=False)# Activate
flyte update trigger custom_cron my_task_env.custom_task --activate --project <project> --domain <domain>
# Deactivate
flyte update trigger custom_cron my_task_env.custom_task --deactivate --project <project> --domain <domain>You can also view and manage your deployed triggers in the Union UI.
Deleting triggers
If you decide that you don’t need a trigger anymore, you can remove the trigger from the task definition and deploy the task again.
Alternatively, delete it directly:
flyte.remote.Trigger.delete("custom_cron", "my_task_env.custom_task")flyte delete trigger custom_cron my_task_env.custom_task --project <project> --domain <domain>