Reputation: 171
I have a list of jobs in my database, when I run php artisan queue:work database
, it processes each job but once it processes the last one, it doesn't seem to stop. I thought doing it this way would mean once the worker has no jobs left, it stops.
Upvotes: 4
Views: 7878
Reputation: 5552
Add the --once
option if you want the worker to exit after running one job:
$ php artisan queue:work --once
As of 5.7 you can use --stop-when-empty
to process all jobs in the queue and then exit:
$ php artisan queue:work --stop-when-empty
Docs: https://laravel.com/docs/5.7/queues#running-the-queue-worker
Note: The default behavior changed around Laravel 5.3. Previously a worker would process one job and exit; it only continued running if the --daemon
option had been used. After 5.3 this became the default behavior, and --daemon
was deprecated.
Upvotes: 13
Reputation: 125
Note that once the queue:work command has started, it will continue to run until it is manually stopped or you close your terminal. Using the --once option will not resolve your problem. Check laravel documentation for more.
The documentation says: The --once option may be used to instruct the worker to only process a single job from the queue.
Upvotes: 1