Colton
07/24/2025, 8:10 PMMarvin
07/24/2025, 8:10 PMMarvin
07/24/2025, 8:11 PMbash
prefect work-pool create "continuous-pool" --type process --concurrency-limit 1
2. Then, modify your flow deployment to use this work pool and a special "run-once" schedule that will trigger the flow to run continuously:
python
from prefect import flow
from prefect.deployments import Deployment
from datetime import timedelta
@flow
def your_flow():
# your flow logic here
pass
# Deploy with a run-once schedule
deployment = Deployment.build_from_flow(
flow=your_flow,
name="continuous-deployment",
work_pool_name="continuous-pool",
schedule={"interval": timedelta(seconds=0)} # This creates an immediate schedule
)
3. Start a worker for your work pool:
bash
prefect worker start -p "continuous-pool"
This approach has several advantages over your current setup:
1. No cancelled runs - the work pool's concurrency limit ensures only one run is active at a time
2. Continuous execution - as soon as one run completes, the next one starts
3. Clean flow run history - you'll only see completed runs, not cancelled ones
4. Better resource management - the worker handles the execution loop instead of relying on the scheduling system
If you need to pause the continuous execution, you can either:
- Pause the work pool
- Stop the worker
- Pause the deployment
This gives you more control without creating the cleanup issues you're experiencing with the cancelled runs approach.
Would you like me to provide more details about any part of this setup, such as how to manage the work pool or deployment programmatically?Colton
07/24/2025, 8:14 PMMarvin
07/24/2025, 8:14 PMMarvin
07/24/2025, 8:16 PMpython
from prefect.deployments import Deployment
from datetime import timedelta
deployment = Deployment(
name="continuous-deployment",
flow=your_flow,
schedule={"interval": timedelta(seconds=1)}, # Minimum practical interval
work_pool_name="continuous-pool",
work_queue_name="default",
work_queue_config={
"late_runs": {"policy": "run"} # Ensures runs aren't skipped
}
)
2. Self-Scheduling Flow:
python
from prefect import flow
from prefect.client import get_client
from datetime import datetime, timedelta
@flow
async def continuous_flow():
# Your flow logic here
# Schedule the next run immediately after completion
async with get_client() as client:
await client.create_flow_run_from_deployment(
deployment_id="your-deployment-id",
scheduled_time=datetime.now()
)
# Deploy with no schedule, let the flow handle its own scheduling
deployment = Deployment(
flow=continuous_flow,
name="self-scheduling-deployment",
work_pool_name="continuous-pool"
)
3. Worker-Level Loop:
python
from prefect import flow
import asyncio
@flow
async def continuous_flow():
while True:
# Your flow logic here
await asyncio.sleep(0) # Minimal cooperative yield
Each approach has trade-offs:
- Option 1 (Minimal Interval): Cleanest but still has a small delay
- Option 2 (Self-Scheduling): More complex but gives you more control
- Option 3 (Worker Loop): Simplest but less manageable through Prefect's UI
Given your current setup and the issue with cancelled runs, I'd recommend trying Option 1 first with a 1-second interval. It's the most maintainable approach and won't flood your flow run history. The late runs policy ensures that if a run takes longer than the interval, the next run will still execute rather than being cancelled.
Would you like me to elaborate on any of these approaches or explore other alternatives?