John Davidson

php - how to run the jobs queue immediately after a job added to queue in laravel?

0 comments
Message:


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?



My Answer:
>job('queue:work')->everyMinute();_}

To run the jobs queue immediately after a job is added to the queue in Laravel, you can use the `dispatch` method to add the job to the queue and then call the `dispatchNow` method to run the job immediately. Here's an example:

php
use App\Jobs\YourJob;

// Add the job to the queue
YourJob::dispatch($data);

// Run the job immediately
YourJob::dispatchNow($data);


This will add the job to the queue and then run it immediately without waiting for the scheduled cron job to run.

Rate this post

3 of 5 based on 8220 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us