How to execute laravel job at low priority?

343 views Asked by At

We have multiple jobs in our laravel application. Currently all jobs are queued at once and they execute one by one. I want this particular job to execute at low priority it means if anyother job comes after that job should be execute first.

BulkPdfPrintLabel::withChain([
                    new MergeLabel($filepath, $manifest_id, $last, $user_id, $user_type)
                ])->dispatch($consignments, $last, $manifest_id, $user_id, $user_type, $filepath);
1

There are 1 answers

2
Babak Asadzadeh On

use this code instead:

// This job is sent to the default queue that you selected in config/app file
BulkPdfPrintLabel::withChain([
                    new MergeLabel($filepath, $manifest_id, $last, $user_id, $user_type)])
          ->dispatch($consignments, $last, $manifest_id, $user_id, $user_type, $filepath);

update

// This job is sent to the "low" queue.("low" is custom and you can change it)
BulkPdfPrintLabel::withChain([
                    new MergeLabel($filepath, $manifest_id, $last, $user_id, $user_type)->onQueue("low")
                ])
        ->dispatch($consignments, $last, $manifest_id, $user_id, $user_type, $filepath);

then run this command to set high priority to your default queue:

php artisan queue:work --queue=high,default

reference laravel queue