Laravel Database Queue Frequency

Viewed 439

Laravel's database queue runs a database query every second to see if there are jobs to be processed.

I know it's not a complex query, but we want to reduce the number of connections hitting our database and we don't have that many jobs right now to consume. We'd like to modify it to run every 15-30 seconds or even longer.

I don't see config option to do something like this in the documentation and haven't found questions that cover this type of use case.

I do see that rate limiting can be enabled when using Redis queues, but our project needs to use the database queue for the time being.

We're on Laravel 5.5 and PHP 7.0 right now and it will be a while before we upgrade to newer versions. I wanted to go with Laravel Horizon, but that requires an upgrade to PHP 7.1.

Any help is appreciated.

1 Answers

From the documentation of laravel

Worker Sleep Duration

When jobs are available on the queue, the worker will keep processing jobs with no delay

in between them. However, the sleep option determines how long (in seconds) the worker

will "sleep" if there are no new jobs available. While sleeping, the worker will not

process any new jobs - the jobs will be processed after the worker wakes up again.

php artisan queue:work --sleep=30
Related