简体   繁体   中英

Laravel pushing jobs into different queue with low priority

Right now I am using Beanstalkd and Laravel forge for my queues which I fire like this: dispatch(new ProcessPodcast($podcast));

But how do I push a queue into a different job that has a low priority? This will only push the queue into a different job but not set the priority: $job = (new ProcessPodcast($podcast))->onQueue('processing'); dispatch($job); $job = (new ProcessPodcast($podcast))->onQueue('processing'); dispatch($job);

And if a queue job has a low priority does it mean that it will be fired later when there arent that many queues or how does low priority jobs work?

dispatch((new Job)->onQueue('high'));

This piece of code create new Job class instance, serialize it and store in queue named high , but it not means that this queue is a special one. Moreover this queue could have less priority than the low queue! This is just a string you use to name queue, of course it's highly recommended to follow some patterns to make code more readable for other developers.

In config/queue.php file you can define the default queue name which will be processed. If you create queue worker using php artisan queue:work command then it'll listen job request on that queue. However, you may overwrite default value using --queue parameter in queue:work command:

php artisan queue:work --queue=high,low # or --queue=high,medium,low

This command also set the priority of the queues. As long as there's any job request in the high queue it will be processed before any request in the low queue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM