I currently registered php artisan schedule:run
in cronjob in cpanel and the schedule method is:
protected function schedule(Schedule $schedule)
{
$schedule->command('queue:work --stop-when-empty')
->cron('* * * * *')
->withoutOverlapping(5);
}
But for my purpose it is necessary to run the jobs immediately,
How can I run php artisan queue:work
immediately after a job added to queue(jobs table) and not after one minute?
2
Answers
the solution is to call
queue:work
on destruct() method of each class that I want to run it's job immediately.For Laravel > 7.x We can dispatch anonymosly
The
WelcomeMessage
should implement/useDispatchable, InteractsWithQueue, Queueable, SerializesModels;
For Laravel 6.x
Instead of dispatching a job class to the queue, you may also dispatch a Closure. This is great for quick, simple tasks that need to be executed outside of the current request cycle:
for more you can read laravel docs https://laravel.com/docs/7.x/queues