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

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

Related

Laravel Run 100 Tasks in a single queue simultaneously

There is a case where I need to run 100 jobs simultaneously . I did my R&D and I came to a point that i need to create multiple queues to run multiple jobs at a time. But I have dynamic number of job count which I need to execute in a given time.
Solution #1 (Create multiple job queues)
php artisan queue:work --queue=myJobQueue & php artisan queue:work --queue=myJobQueue1 & php artisan queue:work --queue=myJobQueue2
Can anyone please suggest the best approach to do this task ?

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

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.

Should php artisan queue:work output all processed jobs?

I'm using redis queue driver in Laravel 6.14. Today I've realized, that when I'm using php artisan queue:work it outputs processed jobs totally randomly. Does anybody come up with the same problem? I thought it outputs all jobs (correctly processed and failed). Thans for any ideas and help.

Running a laravel cron job (locally, to test) using Task Scheduler in Windows 10

I want to run a laravel cron job in order to run a command on windows 10 using task scheduler, I tried to create a basic task in scheduler but it shows running but data doesnt add in db. When I run "php artisan schedule:run" it works perfectly. I am using Laravel and Homestead.
I have adding these two lines while creating the task in scheduler
C:\xampp\php\php.exe (why do we have to add this when I don't even use xampp anymore, so I think this is the part which is giving issues?????)
C:\projects\project-name\artisan schedule:run
I would really appreciate, if someone could guide me through this, thanks.
Update your task scheduler command to this:
C:\xampp\php\php.exe C:\projects\project-name\artisan schedule:run
C:\xampp\php\php.exe does not mean using xampp, we're just using php here which is coincidentally found inside your xampp folder, because we need the executable php to run the file artisan with the parameter schedule:run which is found in C:\projects\project-name\
You can add an environment variable for your executable php so you could just write the command as php C:\path\to\artisan schedule:run.
Also, try to see the logs of task scheduler, so you can see what it tried to do.
As per your issue. Yes, C:\xampp\php\php.exe causes an issue. Try typing in your cmd that command. What happens? It's just paused there. That's also what's happening in your scheduled task.

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

Categories