https://prefect.io logo
Title
s

source_creator

07/19/2019, 9:05 PM
Hi everybody! Is there a way to run multiple schedules? I would like a schedule that runs every hour, and then one that runs twice a day, both that call the same function, but handle the result differently 🙂
c

Chris White

07/19/2019, 9:35 PM
Hi @source_creator! Would a
UnionSchedule
work for your needs? https://docs.prefect.io/api/unreleased/schedules.html#unionschedule You’d probably have to write some custom logic inside your task to handle the result differently for each schedule
s

source_creator

07/19/2019, 9:45 PM
Hi @Chris White,thank you for your reply! With the custom logic approach - how would I detect which schedule called the task, from inside the task?
c

Chris White

07/19/2019, 9:47 PM
i’d recommend pulling the scheduled start time from context and using that to infer which schedule was called: https://docs.prefect.io/api/unreleased/utilities/context.html
s

source_creator

07/19/2019, 10:01 PM
Hmm I think I am missing something. Can I check the context in the Flow? I have setup the
UnionSchedule
, but I am stuck
c

Chris White

07/19/2019, 10:02 PM
from within a task you can check the context; for example,
@task
def get_todays_date():
    today = prefect.context.get("today")
    print(today)
    return today
s

source_creator

07/19/2019, 10:26 PM
I see - I managed to get the scheduled start time from the context, and I can differentiate between the 2 schedules. It's not as nice as I would like, but it's a solution. Thanks Chris!
🚀 1
@Chris White, something I picked up: The microsecond on the start time returned from the context, is not zero, when I specifically set it to zero when defining the
IntervalSchedule
c

Chris White

07/19/2019, 10:46 PM
hmmmmm I’ll have to take a look at that --> I’m not sure why that would be the case; would you mind opening an issue for it on our github repo?
s

source_creator

07/20/2019, 3:21 PM
Hmm seems like it was my misunderstanding, thinking
start_date
passed to
IntervalSchedule
was the same as
scheduled_start_time
from the context in the Task
c

Chris White

08/05/2019, 9:44 PM
@Marvin archive “How can I run multiple schedules on a single Flow?”