Laravel 5.3 queue worker, stop after some time through Jenkins - laravel

In Laravel 5.3.
I'm running through jenkin a command of laravel:
php artisan queue:work
But I need to stop it. Ideally I would like to stop the worker after the queue jobs gets empty, but it's not possible on Laravel 5.3. So another option would be to stop the command after sometime, let's say 1 minute.
How can I stop a process running through jenkins after some time? or stop a php artisan command.
With php artisan queue:restart I can stop all the jobs so I tried:
php artisan queue:work
sleep 60; php artisan queue:restart
But that 2nd line will never get reached because the workers is still running.
Any tip?

you can use some solution form solve it
1.
You save server resources by avoiding booting up the whole app on
every job.
You have to manually restart the worker to reflect any
code change you made in your application.
You can also run:
php artisan queue:work --once
2- This will start an instance of the application, process a single job, and then kill the script.
php artisan queue:listen
The queue:listen command simply runs the queue:work --once command inside an infinite loop, this will cause the following:
An instance of the app is booted up on every loop.
The assigned worker will pick a single job and execute it.
The worker process will be killed.
Using queue:listen ensures that a new instance of the app is created for every job, that means you don't have to manually restart the worker in case you made changes to your code, but also means more server resources will be consumed.

Related

Laravel Job Not being attempted

Laravel is not being attempted (attempts = 0). I have created jobs table and dispatched a job.
The job is now currently being listed in the jobs table but with attempts = 0
I have updated QUEUE_CONNECTION=database and run php artisan config:cache. I have also hit queue:restart but still same result.
Additionally, I have tried with php artisan queue:work --force (without force as well) and php artisan queue:listen as well but still not being attempted.
You have dispatched the job to the property queue. To process this queue run:
php artisan queue:work --queue=property

php artisan queue:work freeze in terminal

I use the queue in my Laravel 5.4 project to send emails in background.
I have created the table for jobs, created the class for the job, and put QUEUE_DRIVER=database in my .env file. When I dispatch my Job, I can see my task in the jobs table. So far so good.
However, when I then execute the command
php artisan queue:work on the webserver - it's freezing and not have any results.
What could be the problem?
This probably is because this is a service that uses the current thread in Ubuntu (from your tag). If you add a &, the process will run in a forked thread.
php artisan queue:work &
Or after a quick google, you can have a look at
nohup php artisan queue:work --daemon &

how to run all queue jobs in one line

Can someone know how can I run in one command to Laravel artisan work on all queue in project?
I know that I can run something like that nohup php artisan queue:work --queue=admin_contact_message_mail,user_get_message_notification,user_get_message_mail --daemon & , but I have a huge list of queues and asks is there any way to call it all in once or I need to list them all to queue run it and listen it?
php artisan queue:listen will do the job!

Should we need run queue listen command every time when we push jobs into Laravel queue?

My question is that if I push jobs in Laravel queue then is I need to run php artisan queue:listen command every time?
No. You have to run php artisan queue:listen only once. If you push jobs in the queue your job has to be executed by the queue.
Run php artisan queue:listen in the background with supervisor.

Laravel 5.1 doesn't process queued job

I am testing the Laravel 5.1 job queue system, which is kept in a db table. I run this command:
php artisan queue:listen
Then I dispatch the queueable job and I can then verify it is in my queue table, but the queued job is never acted upon. Is there something more that I should be doing to get this to work? I have also tried
php artisan queue:work
but that does nothing as well.
I added a queue specifier like so and now it works:
php artisan queue:listen --queue="email"

Resources