Theodor Sjöstedt
08/26/2024, 8:20 AMMarvin
08/26/2024, 8:20 AMpython
from prefect import flow
from prefect.deployments import Deployment
@flow
def my_flow():
# Your flow logic here
deployment = Deployment.build_from_flow(
flow=my_flow,
name="my_deployment",
tags=["my_flow_tag"], # Add a specific tag to your deployment
work_queue_concurrency=1 # Set concurrency limit to 1
)
deployment.apply()
3. Use the Client for Advanced Control: You can programmatically set concurrency limits using the Prefect client, which might give you more control over dynamic scenarios.
* Documentation: https://docs.prefect.io/latest/guides/using-the-client/
4. Potential Issues and Fixes:
* There are known issues with duplicate flow runs in specific environments like Kubernetes. For example, if a flow fails and retries, it can lead to duplicate executions. You can find a related GitHub issue here:
* https://github.com/PrefectHQ/prefect/issues/12509
By setting an appropriate tag and concurrency limit, you can ensure that only one flow run is active at any given time, thus preventing overlapping executions.Theodor Sjöstedt
08/26/2024, 8:25 AMMarvin
08/26/2024, 8:25 AMdeployment.yaml
, you will need to include a work_queue_concurrency
parameter under your deployment configuration. Here is an example structure of how your deployment.yaml
can look:
yaml
# Example deployment.yaml
name: my-deployment
work_pool_name: default-agent-pool
work_queue_name: my-work-queue
tags: ["my_flow_tag"]
schedule:
cron: "*/5 * * * *"
timezone: "UTC"
parameters: {}
infra_overrides: {}
infrastructure:
type: process
env: {}
labels: {}
flow_name: my_flow_name
entrypoint: /path/to/your/flow.py:my_flow_function
path: /path/to/your/project/
# Concurrency Settings
work_queue_concurrency: 1 # This ensures only one run at a time
To apply the new deployment configuration with the concurrency limit:
sh
prefect deployment apply deployment.yaml
This approach sets a concurrency limit on the work queue associated with your deployment, ensuring that only one instance of the flow runs at any one time.
Here are some supporting resources:
* https://docs.prefect.io/latest/guides/global-concurrency-limits/
* https://docs.prefect.io/latest/concepts/deployments-block-based/
You can adjust the remaining parameters in deployment.yaml
to match your specific configuration needs.