Based on the research and GitHub issues, there are a few potential causes for deployments running twice. Let me break this down:
1.
Known Issues:
- There was a specific issue reported with Cloud Run Push work pools in Prefect 2.x where tasks would occasionally run duplicated (see issue #11299)
- This seems to be less common in Prefect 3.x, but proper configuration is crucial
2.
Common Causes:
- Overlapping schedule configurations
- Race conditions in certain infrastructure setups
- Improper configuration of deployment settings
To help diagnose your specific case, I need some additional information:
1. What type of work pool are you using?
2. How is your deployment scheduled (cron expression, interval, etc.)?
3. Are you seeing the duplicate runs consistently or intermittently?
4. Can you see two different flow run IDs in the Prefect UI when this happens?
Some immediate recommendations to prevent duplicate runs:
1.
Check Your Schedule Configuration:
- Ensure there are no overlapping schedule definitions
- Verify the schedule settings in your deployment configuration
2.
Use Concurrency Controls:
- You can set concurrency limits on your flow to ensure only one instance runs at a time
python
@flow(
name="your-flow",
flow_run_name="your-flow-{timestamp}",
version="1",
description="Your flow description",
retries=0,
timeout_seconds=None,
validate_parameters=True,
log_prints=False,
task_runner=None,
persist_result=True,
result_storage=None,
# Add this to limit concurrent runs
flow_run_concurrency=1
)
def your_flow():
...
3.
Monitor Flow Run History:
- Use the Prefect UI to monitor flow run history and identify patterns in when duplicates occur
- Check the flow run IDs and start times to understand if they're truly duplicate runs or just runs starting close together
Could you provide more details about your setup so I can give more specific recommendations?