Prefect 2.0
You set a schedule as part of the DeploymentSpec
:
from prefect.deployments import DeploymentSpec
from prefect.orion.schemas.schedules import IntervalSchedule
from datetime import timedelta
DeploymentSpec(
flow_location="/Developer/workflows/my_flow.py",
name="my-first-deployment",
parameters={"nums": [1, 2, 3, 4]},
schedule=IntervalSchedule(interval=timedelta(minutes=15)),
)
Prefect 1.0
You attach the schedule to your Flow object:
from prefect import Flow
from prefect.schedules import IntervalSchedule
schedule = IntervalSchedule(interval=timedelta(minutes=15))
with Flow("scheduled_flow", schedule=schedule) as flow:
Additionally, you can test the schedule by printing the next schedules as follows:
from prefect.schedules import IntervalSchedule
schedule = IntervalSchedule(interval=timedelta(minutes=15))
for sched in schedule.next(10):
print(sched)