<@ULVA73B9P> When calling .map on a prefect task (...
# ask-marvin
b
@Marvin When calling .map on a prefect task (and running it concurrently), how can I enforce a delay between each task being initiated? Ex I would like a few seconds between each task being started
m
In order to enforce a delay between each task being initiated when using
.map
to run tasks concurrently in Prefect, you could consider using task concurrency limits with task tags to manage the rate at which tasks are allowed to enter the
Running
state. To implement this, you could tag the tasks you want to limit and set a concurrency limit for those tags. If the concurrency slots are filled, any additional tasks attempting to run will be delayed and instructed to retry entering a
Running
state after a specified amount of time. By default, the delay is 30 seconds, but you can configure it using the
PREFECT_TASK_RUN_TAG_CONCURRENCY_SLOT_WAIT_SECONDS
setting. However, it's important to note that this approach doesn't guarantee a fixed delay between each task starting; it rather limits the number of tasks running concurrently. If you need a fixed delay between the initiation of each task, you might need to consider implementing a custom scheduling solution or possibly adding a sleep within the task's execution to enforce a delay. For detailed information on task concurrency limits, you can refer to the Prefect documentation: - Execution behavior and concurrency limits Additionally, If you are interested in global concurrency and rate limits as a way to manage execution, then you can look at this section of the docs: - Global Concurrency Limits and Rate Limits However, as far as I can determine, built-in rate limiting at the task level for fixed initiation delays is not natively supported by Prefect in the manner you've described. For more custom behavior, one alternative might be to introduce delays programmatically in your Prefect flow code.