Yufei Li
11/17/2023, 3:57 PMdef post_hook_save_to_db(flow, flow_run, state):
print(state)
print("This is flow")
print(flow.name) --this would print "test"
print(flow.result) --this would fail. How can I update that to print something as below
# do something
@flow (on_completion=[post_hook_save_to_db], name = "test",persist_result=True)
def test():
return something
Jake Kaplan
11/18/2023, 12:44 AMfrom prefect import flow
from prefect.runtime import flow_run
def on_completion(flow, flow_run, state):
print(f"My flow finished with: {state.result()}")
@flow(log_prints=True, on_completion=[on_completion])
def my_flow():
print(f"I'm in flow: {flow_run.name}")
return 42
which gives me
19:43:24.604 | INFO | prefect.engine - Created flow run 'curious-auk' for flow 'my-flow'
19:43:24.606 | INFO | Flow run 'curious-auk' - View at <https://app.prefect.cloud/.../>
19:43:24.895 | INFO | Flow run 'curious-auk' - I'm in flow: curious-auk
19:43:26.293 | INFO | Flow run 'curious-auk' - Running hook 'on_completion' in response to entering state 'Completed'
19:43:26.299 | INFO | Flow run 'curious-auk' - Hook 'on_completion' finished running successfully
19:43:26.301 | INFO | Flow run 'curious-auk' - Finished in state Completed()
My flow finished with: 42
Yufei Li
11/20/2023, 3:29 PMon_completion
func in the above, the end_time
is None
and the 'state_type'
is StateType.RUNNING
, 'state_name'
is 'Running'
, but when we get the state
from the on_completion
func from above, it is Completed()
?