https://prefect.io logo
Title
d

Deceivious

04/11/2023, 8:49 AM
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

Anthony Head

04/11/2023, 4:16 PM
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:
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`:
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`:
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

Deceivious

04/11/2023, 4:18 PM
Yes. There is create and delete but no update.
n

Nate

04/11/2023, 4:40 PM
hmm, there's also a reset, but not seeing an update. what's your usecase?
d

Deceivious

04/11/2023, 4:43 PM
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

Nate

04/11/2023, 4:54 PM
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

Deceivious

04/11/2023, 4:54 PM
Should I open an issue?
n

Nate

04/11/2023, 4:54 PM
yes please! thank you
d

Deceivious

04/11/2023, 4:55 PM
πŸ˜’aluting_face:will do it tomorrow. Thanks @Nate
n

Nate

04/11/2023, 4:55 PM
πŸ‘
b

Bianca Hoch

04/11/2023, 5:01 PM
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

Deceivious

04/11/2023, 5:02 PM
Thanks I'll test it out
Tested it - the create method does the update as well. thanks
πŸŽ‰ 2