I have certain tasks that need to run on a monthly...
# prefect-community
t
I have certain tasks that need to run on a monthly basis and other tasks that need to run on a daily basis. The outputs from the monthly tasks are inputs to the daily tasks. Can these tasks be run in a single flow or do I need to create two different flows with each flow tied to the different interval schedule (monthly versus daily schedule, respectively)? I can't seem to run two different tasks with different time interval requirements to run in a single flow. Can anyone help?
n
Hi @Tom B! Prefect doesn't attach schedules to individual tasks but instead to flows as a whole, so your idea to create two flows with separate interval schedules makes a lot of sense for what you're trying to accomplish.
t
Perfect! Thanks for your quick reply.
c
Hi @Tom B! This is a great question, and in fact this pattern was one of the initial patterns that inspired Prefect’s caching features. What you could do is configure your first task (the monthly task) to cache for a 1 month time period, while your second task (the daily task) has no caching whatsoever. If you then run your flow on a daily schedule, the first task will only truly rerun once a month (and return the cached output otherwise) while the downstream will rerun each time. For more info check out this concept doc: https://docs.prefect.io/core/concepts/persistence.html#output-caching (Also note that we are improving our caching API in the next few weeks)
n
There's also this very elegant solution from @Chris White 😄
👍 1
c
both work perfectly well, so it’ll boil down to personal preference + the intricacies of your use case!
t
Very interesting. So, just by having the monthly task cache for a 1 month period, that task will only run monthly. Nice.
Just read the documentation...the caching solution is perfect. Thank you!
🎉 2
c
anytime!
@Marvin archive “How can I run a task that only runs daily in the same flow as a task that only runs monthly?”