<@ULVA73B9P> I want a specific scheduled deploymen...
# ask-marvin
m
@Marvin I want a specific scheduled deployment to have concurrency = 1. In other words, I don't want a prior late deployment to overlap a currently scheduled deployment. How to I achieve this?
m
To set a concurrency limit for a specific scheduled deployment in Prefect, ensuring that no prior late deployment overlaps with a currently scheduled deployment, you typically need to use scheduling features that allow for concurrency settings. However, the provided excerpts from the documentation do not explicitly describe how to set such concurrency configurations. It may be necessary to consult the documentation further or review sample configuration files or deployment commands. If Prefect's standard scheduling features do not support your exact concurrency requirements, as a workaround, you could potentially implement a custom mechanism that locks a resource when a flow starts running and only allows a new run when the previous one has released the lock. This can be done using a database or a distributed lock system like Redis or Zookeeper. For a precise solution, I recommend looking deeper into the Prefect documentation, checking the
prefect deployment
CLI command and its options, or even reaching out to Prefect's community support for guidance on how to achieve concurrency control that meets your specific needs. If you would like, I can continue to search for a more definitive answer within Prefect's documentation or by searching through Prefect GitHub issues for similar problems and solutions. Would you like me to do that?
m
In the documentation I cannot find a flow or deployment level concurrency limit. There are task concurrency limits available via tags, however no such tag limits for flows. I cannot use a work-pool or work-queue concurrency limit I think, because my deployment has concurrent async task group flows as subflows. My deployed flow should run only of no other runs from that deployment are PENDING or RUNNING.
n
do other deployments run in the same work pool / queue?
m
I haven't tried, I'm trying to figure out a solution before testing one. What did you find?
The docs say this: > Each work pool can optionally restrict concurrent runs of matching flows. > For example, a work pool with a concurrency limit of 5 will only release new work if fewer than 5 matching runs are currently in a Running or Pending state. But what does 'matching' mean?
Sorry, more specifically -- I can create a single work pool for this particular deployment, and set
concurrency = 1
. But the deployment starts multiple flows as part of async TaskGroup, which is desired. Will the work-pool concurrency then force those subflows to run sequentially?
n
in the situation you described, are these
run_deployment
calls?
starts multiple flows as part of async TaskGroup
if so, yes, they'd run sequentially subject to your work pool concurrency if not, no, since they'd just be running in the same process as your parent (on parent infra) and would not be subject to work pool concurrency
m
yup:
Copy code
@flow
async def run_from_spec(deployment_list):
    async with asyncio.TaskGroup() as tg:
        flow_runs = []
        for deployment in deployment_list:
            task = tg.create_task(
                run_deployment(
                    name=deployment.get('slug')
                    , parameters=deployment.get('params')
                    , tags=tag_from_deploy_object(deployment)
                    , timeout=TIMEOUT_SECONDS
                    )
                )
            await asyncio.sleep(1)
            flow_runs.append(task)
I really want to prevent
run_from_spec
deployment from starting several identical jobs simultaneously after a failure on the server where the agent/work-pool is running. This has happened once recently and I cant find the obvious way to manage this. The
deployment_list
is a list of many deployments that should be run in parallel, so the concurrency limited work-pool is an incomplete solution.