Laravel how to stop/restart workers of a specific queue? - php

I know you can stop all workers in Laravel using queue:restart. But I'm looking for a way to stop all workers working on a specific queue. Something like this:
php artisan queue:restart --queue=my_queue

As far as I read the documentation,
php artisan queue:clear redis --queue=emails
is only available for The SQS, Redis, and database queue drivers.
But this command is clearing, not stopping.

Related

How to run queue:work command in laravel task scheduler?

I have been searching a lot for a solution until I just gave up...
I want to run php artisan queue:work --stop-when-empty command every minute in Laravel task scheduler.
I have tried this
$schedule->command('queue:work --stop-when-empty')->everyMinute()->runInBackground();
but that doesn't seem to work at all...
You are not supposed to run the queue in the scheduler.
The queue should always be up and running (using a process manager, like Supervisor) and pick jobs when they are dispatched (dispatched in a scheduled task or somewhere else, it doesn't matter).
Here is the documentation on this topic: https://laravel.com/docs/8.x/queues#supervisor-configuration

Running laravel queue:work as a background task in windows

I use supervisord to configure and run laravel queues as a background job on the linux machines. One of my customer can only use windows machine due to their company policy.
I want to run laravel queue as a background job on windows. I've came up with this solution below but I am not so sure if it is good way to do it.
forever -c php artisan queue:listen --tries=3
Anyone has tried it in production if yes how was experience with that or anyone has better solution with this situtation?
Any help would be highly appreciated.

Laravel - Execute queued job automatically [duplicate]

This question already has answers here:
How to keep Laravel Queue system running on server
(20 answers)
Closed 4 years ago.
I have jobs to send several emails.
In my controller I call the job:
dispatch(new SendStartPatEmail($data));
And record is saved in table jobs.
But to execute the job I have to run php artisan queued:work manually.
How can I do this automatically?
There are lots of different ways, all depending on the environment that you're using. Laravel tends to recommend using Supervisor to monitor your queue workers and keep them running.
Alternatively, you may wish to have your jobs execute immediately, instead of adding them to a queue. You can do this by setting your queue driver to sync, either in your config:
config/queue.php
'default' => env('QUEUE_DRIVER', 'sync'),
or in your .env file (assuming your config is set up as above)
.env
QUEUE_DRIVER=sync
Already answered here
Yes, if you use Linux you can use for example supervisor which will
run php artisan queue:listen (you need to add this command to
supervisor configuration file) and it will make sure all the time this
command is running.
php artisan queue:work is a simple command that listens to a queue and executes some jobs.
What's the whole concept?
You can run this simple command on the background and all jobs in queue will be executed.
But running a process (queue:work) on the background is not always safe.
Why? because there is always the chance that the process may be terminated or stuck because of a memory leak.
In this case laravel recommends the use of a Supervisor .The supervisor is another process working like a service.It is responsible to check whether the process that php artisan queue:work creates, works normally or it should be restarted.
This way php artisan queue:work runs on the background but there is a mechanism (supervisor) which can restart the process in case something goes wrong
There is the dispatch_now( ... ) method for specifying those jobs you want run synchronously.
I don't care for underscores, so I usually create a helper method dispatchNow( ... ) that calls the underscore version.. 😛

Laravel 5.4 Queue Email

I'm trying to use Laravel Queues for sending emails using the database driver, I have already configured it, run the migration for the "jobs" table and when I run this:
Mail::to($user->email)->queue(new CompraRealizadaAdmin(Cart::content(), $monto_descuento, $envio, $user_array, $direccion, $compra));
A record is added on the "jobs" table, but, how do I run the queue on the database table?, I understand that for triggering it at the moment it is added, I will need to run the command php artisan queue:listen, or if I need to run all the ones that are still on queue, I will use php artisan queue:work.
But how do I run the command without the need to open terminal and keep it open until it has finished...?
I had the idea of creating a schedule and run it every minute and just execute the code: Artisan::call('queue:work'); but that does not work.
Any ideas?
Depending on your needs, preferences and your target OS you can use
supervisord (cross platform)
upstart / systemd (linux)
launchd (OS X)
or alike services to manage your queue worker processes.
In fact Laravel documentation explains in great detail how to install and configure supervisord for this.
It depends on which OS you are working on for Ubuntu or linux you can use supervisor and hup.
butt be careful you have to run hup every time you reboot your machine.
thats how you can run this command. hup php artisan queue:work.
Hope this helps

Laravel queued jobs don't appear in new relic if worker runs as daemon

I noticed that the queued jobs do not appear in new relic as transactions of any kind.
After digging for a bit I found that if I run my artisan queue workers "straight" they do appear just fine but if I run them as daemons (That's what I have set for my artisan queue:work commands in supervisord config) they do not.
Why does it work that way? Is there anything that can be done about it?
I wanna keep them with --daemon set to avoid framework bootstrapping for every single job. However being able to see what's going on in new relic is important as well.
Scheduled commands and regular http requests seem to be tracked just fine.
I'm running Laravel 5.2 on several forge servers with both php 5.6 and 7.0.
Thank you
New Relic added out-of-the-box instrumentation support for Laravel Queues as an experimental feature in version 6.6.0. Check if your agent version is at least 6.6.0 and then add this property to your newrelic.ini:
newrelic.feature_flag=laravel_queue
For more info, check out the release notes:
https://docs.newrelic.com/docs/release-notes/agent-release-notes/php-release-notes/php-agent-660169

Categories