gee
07/15/2025, 10:41 PMMarvin
07/15/2025, 10:41 PMMarvin
07/15/2025, 10:42 PMpython
from prefect import flow, pause_flow_run
@flow
def my_flow():
# Do some work
pause_flow_run() # Simple pause
# Continue work after resume
2. Pausing with Custom Input:
python
from prefect import flow, pause_flow_run
from typing import Dict
@flow
def my_flow():
# Do some work
result = pause_flow_run(
wait_for_input=Dict, # Specify the type of input you expect
timeout=3600, # Maximum time to wait (in seconds)
key="my_custom_event" # Optional key to identify this pause point
)
print(f"Received input: {result}")
# Continue work with result
To resume the flow, you'll need the flow run ID and can use the resume_flow_run
function:
python
from prefect.flow_runs import resume_flow_run
# Resume with custom input
resume_flow_run(
flow_run_id="your-flow-run-id",
run_input={"your": "data"}
)
Key features:
- `timeout`: Specifies how long to wait before timing out (default: 1 hour)
- `poll_interval`: How often to check for resume signals (default: 10 seconds)
- `key`: Optional identifier for the pause point
- `wait_for_input`: The type of input to expect when resuming
You can also resume flows through the Prefect UI by navigating to the paused flow run and providing the required input.
This functionality is particularly useful for:
- Human-in-the-loop workflows
- Waiting for external events or approvals
- Implementing checkpoints in long-running flows
- Debugging or inspection of flow state during execution
The flow will remain in a "Paused" state until either:
1. It's explicitly resumed via resume_flow_run
2. The timeout period is reached
3. The flow run is cancelled
Remember that while a flow is paused, it maintains its execution context, so variables and state are preserved when it resumes.Nate
07/15/2025, 10:45 PMflow_run_id
on hand you want to resume
but you could definitely have an event subscriber and call resume_flow_run
from there when you see your event of interestNate
07/15/2025, 10:46 PMNate
07/15/2025, 10:46 PMNate
07/15/2025, 10:46 PMNate
07/15/2025, 10:46 PMNate
07/15/2025, 10:47 PMNate [5:45 PM]
this is an interesting question and its certainly possible but its not immediately obvious what the "right" way is to make sure you have theon hand you want to resumeflow_run_id
but you could definitely have an event subscriber and callfrom there when you see your event of interestresume_flow_run
[5:46 PM]
actually
[5:46 PM]
there is a built-in resume flow run action
[5:46 PM]
i forgot about that
[5:46 PM]
so it would be a pretty run of the mill automation that you'd make@Marvin how would it look to construct an automation with the
Automation
objectMarvin
07/15/2025, 10:47 PMMarvin
07/15/2025, 10:48 PMpython
from prefect.automations import (
Automation,
EventTrigger, # For triggering on specific events
ResumeFlowRun, # Built-in action to resume flow runs
)
# Create an automation that resumes a flow run when a specific event occurs
automation = Automation(
name="Resume Flow on Custom Event",
description="Automatically resume a paused flow run when a specific event occurs",
triggers=[
EventTrigger(
# Match flows in a paused state
match={
"flow_run.state.type.name": "PAUSED",
# Add any additional matching criteria for your custom event
"your.custom.event.field": "expected_value"
}
)
],
actions=[
ResumeFlowRun( # Built-in action to resume the flow run
# Optionally provide input data that will be passed to the resumed flow
run_input={"your": "data"}
)
]
)
# Save the automation
automation.save()
Key components of this setup:
1. Trigger: The EventTrigger
defines when the automation should fire
- You can match on flow run state (PAUSED
)
- Add additional matching criteria for your custom event
- Can use multiple triggers if needed
2. Action: The ResumeFlowRun
action is built-in and will handle resuming the flow
- Can provide optional input data that will be passed to the flow when it resumes
- The action automatically knows which flow run to resume based on the event context
3. Automation: Combines triggers and actions into a single unit
- Gives it a name and description for identification
- Can be enabled/disabled as needed
- Can be saved and managed through the Prefect UI
This approach has several advantages:
- No need to manually track `flow_run_id`s
- Built-in handling of resume logic
- Can be managed through the Prefect UI
- Can be combined with other triggers and actions for more complex scenarios
You can also manage automations through the Prefect UI, where you can:
- Monitor their status
- Enable/disable them
- View their execution history
- Modify their configuration
This provides a clean, declarative way to handle flow resumption based on custom events without needing to maintain separate event listeners or manually track flow run IDs.gee
07/15/2025, 10:49 PMemit_event
or post webhook, to report when its done. Then that event would resume the flow. I've managed to emit the custom event, parse from the payload into an email notification. Which means I guess I should be able to pass data from the event back the flow. But not sure how to route things to resume the right flowrun id?gee
07/15/2025, 10:51 PMgee
07/15/2025, 10:54 PMAutomation().create()
rather than .save()
?Marvin
07/15/2025, 10:54 PMMarvin
07/15/2025, 10:55 PM.create()
, not .save()
. Here's the corrected version of that part of the code:
python
# Create the automation
automation = Automation(
name="Resume Flow on Custom Event",
description="Automatically resume a paused flow run when a specific event occurs",
triggers=[...],
actions=[...]
).create() # Use create() instead of save()
Thank you for the correction! This is more consistent with Prefect 3.x's API patterns.Nate
07/15/2025, 10:56 PMemit_event
from somewhere 3rd partygee
07/15/2025, 10:58 PM