Roger Webb
08/09/2022, 2:15 PMFlow_A = create_flow_run(
flow_name="Flow A",
project_name="Project A",
task_args=dict(name="Flow A (Execution)"),
scheduled_start_time=pendulum.now().add(minutes=60),
parameters={"Parameter1":"Flow A Parameter 1"}
)
Flow_A_Flag = wait_for_flow_run(
Flow_A,
raise_final_state=True,
stream_logs=True
)
I would expect the parent flow to kick off the flow run.. and then the wait for to wait for an hour before that wait for would succeed. But, it appears that the Flow A actually executes immediately.. not waiting the hour, so the wait_for succeeds after minutes. Is my misunderstanding in the scheduled_Start_time.. or the wait_for?Bianca Hoch
08/09/2022, 5:09 PMBianca Hoch
08/09/2022, 6:11 PMBianca Hoch
08/09/2022, 6:12 PMBianca Hoch
08/09/2022, 6:41 PMBianca Hoch
08/09/2022, 6:41 PMimport prefect
from prefect import task, Flow, Parameter
@task
def hello_task(name):
logger = prefect.context.get("logger")
<http://logger.info|logger.info>(f"Hello {name}!")
with Flow("hello-flow") as flow:
# An optional parameter "people", with a default list of names
people = Parameter("people", default=["Arthur", "Ford", "Marvin"])
# Map `say_hello` across the list of names
hello_task.map(people)
#Register the flow
flow.register(project_name="FirstProject")
Bianca Hoch
08/09/2022, 6:41 PMBianca Hoch
08/09/2022, 6:42 PM#Prior to running/registration, ensure that an agent is running in a seperate terminal/machine in order to intercept the created flow run.
from prefect import Flow
from prefect.tasks.prefect import create_flow_run, wait_for_flow_run
import pendulum
with Flow("parent_flow") as flow:
child_flow_run_id = create_flow_run(
flow_name="hello-flow",
project_name= "FirstProject",
scheduled_start_time = pendulum.now().add(minutes=2), #Replace with 60 minutes.
parameters={"people" : ['Bianca', 'Roger']}
)
child_flowrunview = wait_for_flow_run(
child_flow_run_id,
raise_final_state=True,
stream_logs=True
)
#Register the flow first
#flow.register(project_name="FirstProject")
#Then, run the flow
#flow.run()
Roger Webb
08/09/2022, 6:43 PMRoger Webb
08/09/2022, 6:48 PMRoger Webb
08/09/2022, 6:50 PMBianca Hoch
08/09/2022, 6:53 PMwait_for_flow_run()
can be called for Flow 2 to wait for Flow 1 to finish, and so on and so forth. You won't need to set a 60 minute interval manually, the wait_for_flow_run()
will just fire off as soon as the upstream flow is completed.Bianca Hoch
08/09/2022, 6:53 PMBianca Hoch
08/09/2022, 6:54 PMRoger Webb
08/09/2022, 6:55 PMRoger Webb
08/09/2022, 6:55 PMRoger Webb
08/09/2022, 6:58 PMBianca Hoch
08/09/2022, 7:11 PMRoger Webb
08/09/2022, 7:20 PMRoger Webb
08/09/2022, 7:21 PMRoger Webb
08/09/2022, 7:29 PMBianca Hoch
08/09/2022, 8:00 PMBianca Hoch
08/09/2022, 8:00 PM"parent_flow"
and it creates a flow run for "hello-flow"
which is run 2 minutes afterwards.Roger Webb
08/10/2022, 2:29 PM"parent_flow"
should not run faster than 2 minutes then... cause its waiting for at least 2 minutes for the "hello-flow"
to start. Our entire "parent_flow"
takes 37 minutes. Which would indicate its not waiting an hour for it to start up ..right? The below pic (if its visible) is of the is the equivalent of your "child_flowrunview"
in your parent_flow
. Which the duration (for me should be > 60 minutes (Delay + execution time)).. but was actually 2 minutes and 36 seconds.