如何在低优先级下执行laravel作业



我们的laravel应用程序中有多个作业。目前,所有作业都同时排队,并逐一执行。我希望这个特定的作业以低优先级执行,这意味着如果在该作业之后出现任何其他作业,则应首先执行该作业。

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

使用以下代码:

// 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);

更新

// 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);

然后运行此命令为默认队列设置高优先级:

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

参考laravel队列

最新更新