https://prefect.io logo
Title
a

Arun Giridharan

09/07/2022, 6:10 PM
Is there a way to not run some tasks on scheduled flows, but run it on non-scheduled flows?
1
m

Mason Menges

09/07/2022, 6:58 PM
assuming this is for Prefect 2 you could do something like this
@flow
def test_flow():
    flow_run = prefect.context.get_run_context().flow_run

    if flow_run.auto_scheduled == False:
        some_task()
    else:
        other_task()
This would only run
some_task
if the flow run wasn't automatically scheduled, i.e it was triggered manually or through some other api call like create_flow_run_from_deployment()
a

Arun Giridharan

09/07/2022, 6:59 PM
@Mason Menges this is for Prefect 1
m

Mason Menges

09/07/2022, 7:34 PM
I think it's probably still doable in Prefect 1 it might just require some more lift, I haven't tried this before specifically so this would just be my thoughts on it but you may be able to leverage the context/config to do this https://docs-v1.prefect.io/api/latest/utilities/context.html#context-2 specifically the scheduled_start_time since that defaults to Now for unscheduled runs, Another option might be to try setting a parameter for the flow that defaults to True, and you can set it to false when doing a manual run https://docs-v1.prefect.io/core/concepts/parameters.html This is probably the more pythonic way of doing it but requires a tad bit more setup in the flow.
:gratitude-thank-you: 1