Is there a Prefect cloud/UI equivalent of this? <h...
# ask-community
j
Is there a Prefect cloud/UI equivalent of this? https://docs.prefect.io/core/idioms/flow-to-flow.html
k
Not sure what you mean on the Prefect Cloud. If you mean like a drag and drop, kind of, but using Python will be a lot easier. On standard plan and up, there are automations that have actions that get performed when a Flow changes state. So it would be a matter of saying when Flow A finishes, trigger Flow B. But I don’t think that’s good because if you have subflows, it kills the reusability of just running Flow A independently. Using the Python script in that docs page will be much better. Note those Flows need to be registered beforehand to use them with
create_flow_run
UI-based Flow builders are in considering for Prefect 2.0 though.
j
Let's say that right now I have Flow A scheduled to run at 2PM, then Flow B at 230 and Flow C at 3PM. Each is dependent on the other. I would then create a flow of flows document and upload it to the same project folder, right? Can I set them to run "ahead" of schedule, provided the upstream flow finishes in time?
k
In this case I would use a “Main Flow”. If Flow A, B and C are registered already. You can do:
Copy code
with Flow(...) as flow:
    a = create_flow_run(project_name="...",flow_name="Flow_A",scheduled_start_time="...")
    a_wait = wait_for_flow_run(a)
    b = create_flow_run(project_name="...",flow_name="Flow_B",scheduled_start_time="...", upstream_tasks[a_wait])
    b_wait = wait_for_flow_run(b)
So you make Flow B wait for Flow A to finish and you give it a scheduled_start_time. If the scheduled_start_time already passed, the flow will run immediately. Otherwise it will wait for the time before running.
j
On the above, is that identical to the flow of flows in the documentation? Or are you saying to add that to the Last flow?
k
Pretty identical except I added the scheduled_start_time so that you can run them at 2 pm, 2:30 pm, and 3 pm. But if that’s not important, then take out the scheduled start time and run chain the dependencies and they’ll run one after another. These flows won’t need schedules then, you can just schedule the main flow
j
So if I am in prefect cloud, I would see all the flows but only one (1) with a schedule turned on, that one being the primary flow. But they would all still run daily or however I specified it in the "flow of flows"
k
Yes exactly. If “Main Flow” runs everyday at 2 pm, Flow A, B, and C will still run daily even with no scheduled because Main Flow kicks off their runs
j
and any cloud hooks i had configured to show success/failure on the "child" flows or whatever would still run
That's neat
Thank you!
k
Yeah exactly because they are on the Flow level. So A, B, and C can even have different Docker images or RunConfigs. 🙂
j
That's tremendous, thank you!
@Kevin Kho one other quick question, if I want to re-use a task but label it differently, can I just change the "name"?
I would change "Name" in the flow itself in this example)
Copy code
@task(name = "Load", log_stdout=True, max_retries=3, retry_delay=timedelta(seconds=10))
e.x.
Copy code
with flow():
load(name="load1", db_table=table1)
load(name="load2", db_table=table2)
k
You can change the task name in the Flow block like this:
Copy code
@task(name = "abc")
def abc(x):
    return x + 1

with Flow(..) as flow:
    abc(1, task_args={"name":"bcd})
task_args is a dict of items that would go in the
@task
decorator
j
Lovely, thank you