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.

In Flyte 1 these were configured with a 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