Philip MacMenamin
11/07/2022, 9:28 PMwith Flow(
"...",
state_handlers=[utils.notify_completion, utils.notify_running],...
with
def notify_running(flow: Flow, old_state, new_state) -> State:
And I could ask what the new state is doing. eg if
if new_state.is_running()
I'm reading https://docs.prefect.io/concepts/states/to try to work out how to capture these flow level state changes and am struggling.
Any pointers?Zanie
state_handlers
.Zanie
Philip MacMenamin
11/07/2022, 9:32 PMZanie
Philip MacMenamin
11/07/2022, 9:33 PMZanie
Zanie
Zanie
Philip MacMenamin
11/07/2022, 9:35 PMZanie
Philip MacMenamin
11/07/2022, 9:36 PMZanie
Philip MacMenamin
11/07/2022, 9:36 PMPhilip MacMenamin
11/07/2022, 9:37 PMZanie
Zanie
from prefect import flow
from functools import wraps
def notify(fn):
@wraps(fn)
def wrapper(*args, **kwargs):
print("Starting!")
result = fn()
print("Ending!")
return result
return wrapper
@flow
@notify
def foo():
return "hi!"
if __name__ == "__main__":
foo()
Zanie
❯ PREFECT_DEBUG_MODE=1 python example.py
15:39:01.803 | DEBUG | prefect.client - Using ephemeral application with database at sqlite+aiosqlite:////Users/mz/.prefect/orion.db
15:39:01.853 | INFO | prefect.engine - Created flow run 'gorgeous-waxbill' for flow 'foo'
15:39:01.854 | DEBUG | Flow run 'gorgeous-waxbill' - Starting 'ConcurrentTaskRunner'; submitted tasks will be run concurrently...
15:39:01.855 | DEBUG | prefect.task_runner.concurrent - Starting task runner...
15:39:01.855 | DEBUG | prefect.client - Using ephemeral application with database at sqlite+aiosqlite:////Users/mz/.prefect/orion.db
15:39:01.987 | DEBUG | Flow run 'gorgeous-waxbill' - Executing flow 'foo' for flow run 'gorgeous-waxbill'...
15:39:01.987 | DEBUG | Flow run 'gorgeous-waxbill' - Executing foo()
Starting!
Ending!
15:39:02.000 | DEBUG | prefect.task_runner.concurrent - Shutting down task runner...
15:39:02.000 | INFO | Flow run 'gorgeous-waxbill' - Finished in state Completed(message=None, type=COMPLETED, result='hi!')
15:39:02.001 | DEBUG | prefect.client - Using ephemeral application with database at sqlite+aiosqlite:////Users/mz/.prefect/orion.db
Philip MacMenamin
11/07/2022, 9:39 PMZanie
Philip MacMenamin
11/07/2022, 9:39 PMPhilip MacMenamin
11/07/2022, 9:40 PMZanie
Philip MacMenamin
11/07/2022, 9:40 PMZanie
Zanie
Philip MacMenamin
11/07/2022, 9:41 PM