Hi everybody! Is there a way to run multiple sche...
# ask-community
s
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
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
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
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
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
from within a task you can check the context; for example,
Copy code
@task
def get_todays_date():
    today = prefect.context.get("today")
    print(today)
    return today
s
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
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
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
@Marvin archive “How can I run multiple schedules on a single Flow?”