You use triggers to start a flow. They can be scheduled or triggered by an event. Kestra core provides three types of triggers:
- Schedule
- Trigger your flow based on a cron expression
- Flow trigger
- Trigger your flow based on another flow end
- Webhook
- Trigger your flow based on an HTTP request
Many other triggers are available from the plugins, such as triggers based on file creation or a message queue.
Defining triggers
The Trigger definition is close to the task definition. We define them in the triggers
section of the flow. And as a Task, it contains an id
, a type
, and some properties related to his type. A Flow can have multiple Triggers.
The below triggers will start the flow every day at 10 am or when the trigger-flow
flow ends.
yaml
triggers:
- id: schedule
type: io.kestra.core.models.triggers.types.Schedule
cron: 0 10 * * *
- id: listenFlow
type: io.kestra.core.models.triggers.types.Flow
conditions:
- type: io.kestra.core.models.conditions.types.ExecutionFlowCondition
namespace: io.kestra.tutorial
flowId: trigger-flow
Add a trigger to your flow
Let's schedule our flow. This trigger will start our flow every Monday at 10 am.
yaml
triggers:
- id: schedule
type: io.kestra.core.models.triggers.types.Schedule
cron: 0 10 * * 1
Click here to see the full flow
yaml
id: kestra-tutorial
namespace: io.kestra.tutorial
labels:
env: PRD
description: |
# Kestra Tutorial
As you notice, we can use markdown here.
tasks:
- id: download
type: io.kestra.plugin.fs.http.Download
uri: "https://gist.githubusercontent.com/tchiotludo/2b7f28f4f507074e60150aedb028e074/raw/6b6348c4f912e79e3ffccaf944fd019bf51cba30/conso-elec-gaz-annuelle-par-naf-agregee-region.csv"
- id: analyze-data
type: io.kestra.core.tasks.scripts.Python
runner: DOCKER
dockerOptions:
image: python
inputFiles:
data.csv: "{{outputs.download.uri}}"
main.py: |
import pandas as pd
from kestra import Kestra
data = pd.read_csv("data.csv", sep=";")
data.info()
sumOfConsumption = data['conso'].sum()
Kestra.outputs({'sumOfConsumption': int(sumOfConsumption)})
requirements:
- pandas
triggers:
- id: schedule
type: io.kestra.core.models.triggers.types.Schedule
cron: 0 10 * * *