-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathbasic.py
More file actions
34 lines (22 loc) · 913 Bytes
/
basic.py
File metadata and controls
34 lines (22 loc) · 913 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
"""
Example of a simple task that runs on a schedule using Flyte's Cron trigger.
"""
from datetime import datetime
import flyte
env = flyte.TaskEnvironment(
name="example_task",
)
@env.task(triggers=flyte.Trigger.hourly()) # Every hour
def example_task(trigger_time: datetime, x: int = 1) -> str:
return f"Task executed at {trigger_time.isoformat()} with x={x}"
custom_trigger = flyte.Trigger(
"custom_cron",
flyte.Cron("0 0 * * *", timezone="Europe/London"), # Runs once every day at midnight London time
inputs={"start_time": flyte.TriggerTime, "x": 1},
)
@env.task(triggers=(custom_trigger, flyte.Trigger.minutely("start_time"))) # Custom trigger and every minute
def custom_task(start_time: datetime, x: int = 11) -> str:
return f"Custom task executed at {start_time.isoformat()} with x={x}"
if __name__ == "__main__":
flyte.init_from_config()
flyte.deploy(env)