Sodaman
03/13/2024, 7:38 PMMarvin
03/13/2024, 7:38 PMpython
from prefect import flow, concurrency
@flow
def my_flow():
with concurrency("database", occupy=1):
# Your flow logic here
This code snippet uses the concurrency
context manager to specify a concurrency limit with the key "database" such that only one instance with this key can run at a time.
For more details, you can visit Prefect's guide on global concurrency limits:
Global Concurrency Limits
Unfortunately, I could not find a direct reference to preventing a re-run using the to_deployment()
method after applying the @Flow
decorator. If this is a common issue, consider exploring Prefect's official documentation or forums for more recent updates or patterns that may fit your scenario.Sodaman
03/13/2024, 8:07 PMSodaman
03/13/2024, 8:09 PMMarvin
03/13/2024, 8:09 PMconcurrency
context manager within a task function.
However, as the concept of concurrency limits is to ensure certain resource constraints such as database connections are not exceeded, it is reasonable to infer that if you want to apply concurrency limits to control the flow runs as a whole, you would apply similar principles but at the level where you orchestrate flow runs rather than within the flow definition itself.
To implement concurrency control at the flow level, you would typically set up scheduling and execution parameters outside of the flow definition that manage how and when flow runs are initiated. This might involve using Prefect's orchestration tools to control run concurrency, perhaps through the UI or CLI.
For more precise guidance and if there have been updates to Prefect 2.x that include flow-level concurrency control, I recommend checking the latest version of the Prefect documentation on concurrency limits.
If this doesn't resolve your inquiry or if you're looking for features specific to Prefect 2.x (Orion
), it might also be helpful to post this question in the Prefect community Slack or Prefect Discuss forums where you can get tailored advice from the developers and broader Prefect community.