Prioritizing Queued Jobs in Laravel (Beanstalkd Driver)

When jobs are dispatched and queued in Laravel, they are processed in the order that they were dispatched. I needed a way to process specific jobs before others, irrespective of order they were dispatched in. I couldn’t find a built-in or third-party solution for this so I wrote this package which introduces a middle layer between queueing and dispatching. Jobs are queued up by inserting them into a priority queue (stored in a database table). As queue workers become available, jobs are then dispatched in order of highest priority.

Here’s an example of how that looks like.


// Old way
dispatch((new ConvertImage)->onQueue('images')); 

// New way (priority passed as second parameter)
PriorityQueue::queue('images')->insert(new ConvertImage, 10);

A detailed explanation is found in the README of the repository. Visit the github repository here.

Leave a Reply

Your email address will not be published. Required fields are marked *