laravel / ideas

Issues board used for Laravel internals discussions.
939 stars 28 forks source link

set interval between jobs in the queue #2574

Closed josuelrocha closed 3 years ago

josuelrocha commented 3 years ago

Hi,

I would like to make a suggestion to be able to add an interval time between jobs to run, this configuration could be a property of the worker.

for example: php artisan queue:work --queue=emails --interval=5

the behavior would be as follows:

job 1 //send email
wait 5 seconds //sleep($interval)
job 2 //send email
wait 5 seconds //sleep($interval)
job 3 //send email
wait 5 seconds //sleep($interval)
...

This is different from the rate limit. For example, I have an email server that doesn't allow you to send too many emails sequentially, so you need to pause before sending the next one. So that way it would be very useful.

Currently I solved this problem by adding a sleep(5) at the end of the job's handle method, but it doesn't seem to be pleasant.

paras-malhotra commented 3 years ago

This already exists. It's the --rest param (in milliseconds) for the queue:work command.

josuelrocha commented 3 years ago

https://github.com/laravel/framework/blob/100ed71fe11a25908539c57368a048ec80c6123d/src/Illuminate/Queue/WorkerOptions.php#L47

@paras-malhotra thanks for the guidance, it really already exists.