Run tasks automatically on a schedule, or save named launch configurations to fire on demand.
Triggers
A trigger is a named, pre-bound way to run a task. It carries the inputs, env vars, queue, notifications, and other run settings that a run started through it should use. A trigger can also carry an automation that fires it on its own, such as a schedule. A trigger with no automation is fired on demand only.
import flyte
from datetime import datetime
env = flyte.TaskEnvironment(name="trigger_env")
@env.task(triggers=flyte.Trigger.hourly("trigger_time"))
def hourly_task(trigger_time: datetime, x: int = 1) -> str:
return f"Hourly example executed at {trigger_time.isoformat()} with x={x}"Deploy the task with flyte deploy and the trigger starts creating runs every hour.
LaunchPlan (the flytekit.LaunchPlan API) and CronSchedule. Flyte 2 replaces them with flyte.Trigger and flyte.Cron.Types of automation
The automation argument of flyte.Trigger decides what fires it. Each kind can also bind a value into one of the task’s inputs.
| Kind | Automation | Fires when | Binds into inputs | Details |
|---|---|---|---|---|
| Scheduled | flyte.Cron("0 9 * * *", timezone=...) |
A cron expression matches | flyte.TriggerTime |
Schedule triggers |
| Scheduled | flyte.FixedRate(60, start_time=...) |
Every N minutes | flyte.TriggerTime |
Schedule triggers |
| Scheduled | flyte.Trigger.hourly(), daily(), weekly(), monthly() |
Predefined cron shortcuts | flyte.TriggerTime |
Predefined schedules |
| Manual | None | Only when fired from the UI or with flyte.run(trigger) |
None | Manual triggers |
Every trigger, whatever its automation, can also be fired on demand.
Support is coming for other trigger types, such as:
- Webhook triggers: Hit an API endpoint to run your task.
- Artifact triggers: Run a task when a specific artifact is produced.
In this section
flyte.Trigger on a task, bind its inputs, and attach several triggers to one task.
Schedule triggers
Run a task on a cron expression or a fixed interval with flyte.Cron, flyte.FixedRate, or a predefined schedule.
When scheduled runs start
When the first run of a cron or fixed-rate trigger happens, depending on activation and start_time.
Manual triggers and firing on demand
Save named launch configurations for a task with triggers that have no automation, and fire any trigger from the UI or Python.
Deploy and manage triggers
Deploy triggers with their task, activate or deactivate them, and delete them.