Hello, Question related to Prefect API: Is there ...
# prefect-community
d
Hello, Question related to Prefect API: Is there any way to update an existing
task concurrency limit tag
?
1
Say I have created one with a limit of
1
and now I want to update it to
2
. The only way I see now is to delete the
limit tag
and create a new one but if I have loads of tasks waiting for open slot and I do that, during the interval the
limit tag
is recreated, the tasks will start executing.
a
To update an existing task concurrency limit, you can use the Prefect Python client. Here's an example of how to set a new concurrency limit for a tag:
Copy code
python
from prefect.client import get_client

async with get_client() as client:
    # set a new concurrency limit on the 'small_instance' tag
    limit_id = await client.create_concurrency_limit(
        tag="small_instance",
        concurrency_limit=10
    )
To remove all concurrency limits on a tag, you can use `PrefectClient.delete_concurrency_limit_by_tag`:
Copy code
python
async with get_client() as client:
    # remove a concurrency limit on the 'small_instance' tag
    await client.delete_concurrency_limit_by_tag(tag="small_instance")
If you want to query the currently set limit on a tag, use `PrefectClient.read_concurrency_limit`:
Copy code
python
async with get_client() as client:
    # read the concurrency limit on the 'small_instance' tag
    limit = await client.read_concurrency_limit(tag="small_instance")
For more information, you can refer to the [Prefect documentation on tasks](https://docs.prefect.io/latest/concepts/tasks/) and the [Task Run Concurrency page](https://docs.prefect.io/latest/ui/task-concurrency/).
d
Yes. There is create and delete but no update.
n
hmm, there's also a reset, but not seeing an update. what's your usecase?
d
I am writing everything as code. So i write config for all work queues and limits. On major releases of our code we reverify everything, create if doest exist and update if it exists.
If the limit in config has changed, i want to update the limit without deleting the concurrency tag limit.
n
unfortunately, I'm not sure its directly possible to do this right now. there is no route for updating concurrency limits, only create / read / delete / reset
d
Should I open an issue?
n
yes please! thank you
d
🫡will do it tomorrow. Thanks @Nate
n
👍
b
Just chiming in here, I think that
create_concurrency_limit**
currently overwrites the concurrency limit for an existing tag. You just have to pass in the tag's name and the new concurrency limit value.
🙌 2
sorry, typo'd
d
Thanks I'll test it out
Tested it - the create method does the update as well. thanks
🎉 2