This example uses webhooks, which are only available in Prefect Cloud.
- Fix the bug in a pull request
- Merge the PR
- Manually retry the failed flow run
Prerequisites
- A Prefect Cloud workspace
- A GitHub repository with webhook access
- A failed flow run you want to resume
Step 1: Create a Prefect webhook
Create a webhook in Prefect Cloud that transforms GitHub PR events into Prefect events. The webhook template extracts the flow run ID from the PR body when present. Navigate to your workspace’s Webhooks page and create a new webhook with this template:flow_run_id filter to extract a flow run UUID from any Prefect Cloud URL
in the PR body. If no flow run URL is found, it falls back to github.pr.<number>.
The pr.merged label enables filtering for merged PRs only.
Copy the webhook URL for the next step.
Step 2: Configure GitHub webhook
In your GitHub repository:- Go to Settings → Webhooks → Add webhook
- Set the Payload URL to your Prefect webhook URL
- Set Content type to
application/json - Under Which events would you like to trigger this webhook?, select Let me select individual events and check Pull requests
- Click Add webhook
Step 3: Create an automation
Create an automation that triggers when a PR is merged and the event contains a flow run ID. Navigate to your workspace’s Automations page and create a new automation: Trigger configuration:- Trigger type: Event
- Event name:
github.pull_request.closed - Resource: Match
prefect.resource.idstarting withprefect.flow-run. - Resource labels: Match
pr.mergedequalsTrue
- Action type: Change flow run state
- New state: Scheduled
- Force: Yes (required to transition from Failed state)
prefect.resource.id and changes
its state to resume execution.
Example flow
Here’s a simple flow that reads configuration and can fail based on its contents:Using the workflow
When this flow fails:- Create a PR to fix the issue (e.g., fix
config.json) - Include the flow run URL in the PR body:
- Merge the PR
- The automation triggers and resumes the flow run
How it works
- GitHub sends webhook: When a PR is closed, GitHub sends a POST request to your Prefect webhook
- Webhook transforms event: The Jinja template extracts the flow run ID from the PR body and creates a Prefect event with
prefect.resource.idset toprefect.flow-run.<uuid> - Automation matches: The automation triggers on
github.pull_request.closedevents wherepr.mergedisTrueand the resource ID matches a flow run - State change: The automation changes the flow run state to
Scheduled, which resumes execution