Run tasks automatically on a schedule or in reaction to new data, 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())
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 |
| Reactive | flyte.OnArtifact("model") |
Any new version of an artifact is published | flyte.TriggeredArtifact |
Trigger on new artifact versions |
| Reactive | flyte.OnArtifact("model", version="v2") |
That exact version is published | flyte.TriggeredArtifact |
Trigger on new artifact versions |
| Reactive | flyte.OnArtifact("raw_events", region="us") |
A new version lands in a matching partition | flyte.TriggeredArtifact, flyte.TriggeredPartition |
Trigger on partitions |
| 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 webhook triggers, which will hit an API endpoint to run your task.
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.
Trigger on new artifact versions
Run a task automatically whenever a new version of an artifact lands, using flyte.OnArtifact. It fires no matter who published the version.
Trigger on partitions
Fire an artifact trigger only for matching partitions with flyte.OnArtifact, and pass the partition values into the task with flyte.TriggeredPartition.
Notifications
Send Slack, email, Teams, or webhook notifications when a run started by a trigger ends.
Deploy and manage triggers
Deploy triggers with their task, activate or deactivate them, and delete them.