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!
Related
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.
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 &
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.
In terminal if I run php artisan queue:work --tries=3 &
the command will start and it will be sent to background...
but in Laravel if I run Artisan::call('queue:work', ['--option' => 'tries=3'.' &']);
I get this error:
Symfony\Component\Console\Exception\InvalidOptionException: The "--option" option does not exist. in /var/www/html/laravel/exercise/vendor/symfony/console/Input/ArrayInput.php:172
Stack trace:
#0 /var/www/html/laravel/exercise/vendor/symfony/console/Input/ArrayInput.php(134): Symfony\Component\Console\Input\ArrayInput->addLongOption('option', 'tries=1 &')
and if i run Artisan::queue('queue:work');
the command works but it's an infinite loop and it just blocks the whole app.
So is there a way to run the queue:work from the app and send it to background like in terminal?
Two things should be seperated here:
Queueing jobs
Artisan::queue('command:name', $options);
This tells Artisan to, whenever the queue processor is working, execute command:name.
Running an artisan command
From my perspective, this is the thing you are looking for. To execute a specific Artisan command from your app, you can also use the call method on the Artisan facade.
Artisan::call('queue:work');
Another problem is that you are specifying the options in the wrong way. Try this:
Artisan::call('queue:work', ['--tries' => 3]);
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"