https://prefect.io logo
Title
m

max

09/21/2022, 6:58 AM
Hey! I want to schedule my flows with IntervalSchedule. How can I make first run right after the flow is deployed?
1
s

Stéphan Taljaard

09/21/2022, 9:33 AM
Hi I haven't tested with IntervalSchedule, but saw with Cron it automatically enables the deployment and schedules new flows after I apply the deployment (it takes a minute to show up in the queue)
m

max

09/21/2022, 10:49 AM
My question was about starting the first flow run just after the deploying it. I solved this by making Deployment this way:
my_flow_deployment = Deployment(
    flow=my_flow,
    flow_runner=SubprocessFlowRunner(),
    schedule=IntervalSchedule(
        interval=datetime.timedelta(hours=3),
        anchor_date=datetime.datetime.utcnow().replace(tzinfo=utc)
    ),
)
and deploying like this:
deployment_id = await my_flow_deployment.create(client=prefect_client)
await prefect_client.create_flow_run_from_deployment(deployment_id=deployment_id)
ps. if I remove running flow after the deployment, prefect server will run my flow only at the next date, but I wanted to run it just when deployed.
🚀 2
🙌 2