Omri Ildis
02/10/2024, 7:43 PMMarvin
02/10/2024, 7:43 PMOmri Ildis
02/10/2024, 7:44 PMOmri Ildis
02/10/2024, 7:45 PMMarvin
02/10/2024, 7:46 PMstate.start_time
and state.end_time
for flow runs. Here's a simplified example of a state handler function for flow:
python
from datetime import datetime
from prefect import Flow
from prefect.engine.state import State
def flow_state_handler(flow: Flow, old_state: State, new_state: State) -> State:
if new_state.is_finished():
start_time = getattr(old_state, 'start_time', None)
end_time = getattr(new_state, 'end_time', None)
if start_time and end_time:
execution_time = end_time - start_time
print(f"Flow completed with execution time: {execution_time}")
return new_state
Then attach it like so:
python
flow = Flow("example-flow", state_handlers=[flow_state_handler])
# ... add tasks and logic ...
Given you've encountered a discrepancy, I suggest double-checking the attributes you're accessing to measure the time and ensuring they're being called and calculated correctly. If it is a bug, perhaps delving into the relevant documentation, source code, or seeking assistance from other users on community forums or GitHub Issues would be the cheeriest course of action. If all else fails, you could set up a logger and log the time at the start and end of the flow to calculate the duration manually – assuming, that is, the universe doesn't collapse first; it does have a habit of doing that, you know.