https://prefect.io logo
Title
j

jcozar

02/07/2023, 1:19 PM
Hi! Just a quick question about prefect v2: is it possible to parametrize flow runs based on the scheduler that triggered its execution, like in Prefect v.1? Thanks!
c

Christopher Boyd

02/07/2023, 1:30 PM
Can you elaborate what you mean? Flow runs can be parameterized , and the agent / execution they are picked up by is dependent on the queue assigned . Are you referring to something further ?
j

jcozar

02/07/2023, 1:46 PM
Of course: I have a flow that sends a report by email and I need to schedule it everyday. However, I don't want to be sent on weekends, instead on mondays I want to execute 3 flow runs: saturday, sunday and monday. In prefect 1 I did it like this, using 3 CronClocks with custom parametrization that I used to work with the correct date internally:
schedule = Schedule(
        # everyday at 8:30 am (Europe/Madrid)
        clocks=[
            CronClock("30 8 * * 1-5", start_date=pendulum.datetime(2021, 1, 1, tz="Europe/Madrid")),
            # for saturays sent on monday (10 minutes before than monday mail)
            CronClock("20 8 * * 1", start_date=pendulum.datetime(2021, 1, 1, tz="Europe/Madrid"), parameter_defaults={"subtract_days": 2}),
            # for sundays sent on monday (5 minutes before than monday mail)
            CronClock("25 8 * * 1", start_date=pendulum.datetime(2021, 1, 1, tz="Europe/Madrid"), parameter_defaults={"subtract_days": 1}),
        ]
    )
I see that I can create 3 deployments, one for business days, other for saturdays and other for sundays following the same approach (deployments allow to overwrite defaults parameters). However I need 3 deployments, not just 1 with 3 schedulers, which is a bit uglier 🙂
c

Christopher Boyd

02/07/2023, 1:52 PM
You can do Deployment.build_from_flow and customize your parameters in line ?
j

jcozar

02/07/2023, 2:05 PM
Yes thank you. I can use three deployments one for each use case. I will do like that