-1

I am running a web application on Laravel 5.5. I have a requirement to run the jobs in a queue and then stop the queue. The queue cannot be allowed to stay running.

I am running the below command but this just endlessly carries on.

php artisan queue:work --tries=3

If I use supervisord can I stop the queue from inside the Laravel application.

Any help is really appreciated.

lagbox
  • 48,571
  • 8
  • 72
  • 83
Rutnet
  • 1,533
  • 5
  • 26
  • 48
  • Seems jank but i'd be curious if you could call the queue:restart artisan command ```Artisan::call('queue:restart');``` or queuing it, ```Artisan::queue('queue:restart');```. No clue if that would work, just shooting from the hip. Without supervisor or something running, it should force the workers to "die gracefully" in theory™ – Giovanni S Sep 29 '20 at 22:35
  • In theory `php artisan queue:work --once` will just process one job, but if you're triggering this as part of a request you might as well just be using the sync queue instead – apokryfos Sep 29 '20 at 23:07

1 Answers1

1

From the documentation:

Processing All Queued Jobs & Then Exiting

The --stop-when-empty option may be used to instruct the worker to process all jobs and then exit gracefully. This option can be useful when working Laravel queues within a Docker container if you wish to shutdown the container after the queue is empty:

Try php artisan queue:work --tries=3 --stop-when-empty

https://laravel.com/docs/8.x/queues#running-the-queue-worker

Giovanni S
  • 2,050
  • 18
  • 33