Problem/Motivation
Many queueing systems (such as ActiveMQ, Beanstalkd etc) allow items to be given a priority when they are added to a queue, in order to allow applications to determine whether an item should be processed before others. The original issue to get queue API into D7 (http://drupal.org/node/391340) stated:
Queue cleanup and priorities are not yet there -- there is always a next, patch.
Therefore, the core queue API should allow createItem() to set a priority on an item.
Proposed resolution
Add a priority parameter to the createItem() method in the Drupal\Core\Queue\QueueInterface. Default this priority to zero to allow all existing queue usage to continue to work unmodified.
Remaining tasks
Get it RTBC and comitted :-)
User interface changes
None.
API changes
Update to Queue API (Drupal\Core\Queue\QueueInterface), and to the MemoryQueue and DatabaseQueue implementations in Core.
Original issue summary:
Many queueing systems (such as ActiveMQ, Beanstalkd etc) allow items to be given a priority when they are added to a queue, in order to allow applications to determine whether an item should be processed before others. The original issue to get queue API into D7 (http://drupal.org/node/391340) stated:
Queue cleanup and priorities are not yet there -- there is always a next, patch.
Therefore, this issue proposes a patch to the core queue API, allowing createItem() to set a priority. It exposes this in the Database Queue implementation, with priority used as an additional parameter to sort items by when claiming.
No change has so far been made to the MemoryQueue implementation, although this should also be considered.
First aim is to get a change in which is transparent and allows all existing tests to pass, a follow up will add tests to test that the queue prioritisation has the desired effect but I wanted to get views on the change before progressing.
Comments
Comment #1
tsphethean commentedFirst patch for testing.
Comment #2
tsphethean commentedComment #4
tsphethean commentedAdd update hook to install priority column on upgraded sites. Will hopefully fix all the failing upgrade tests.
Comment #6
tsphethean commentedHmm. Test both in test bot and locally seem to be failing at the point where update.php is building it's batch, because its inserting into the queue table (with new priority field) before the update has run to add the new column.
How do you get around this? I could add something to update_fix_compatibility() or update_fix_d8_requirements() in update.inc - does that seem reasonable?
Comment #7
tsphethean commentedInitial add db_add_field to update_fix_d8_requirements() seems to fix failing upgrade tests locally. Will see what testbot thinks and then we can discuss if this is the right place to fix it...
Comment #8
tsphethean commentedComment #9
tsphethean commentedUpdated patch with (locally) passing tests and a solution for the Memory queue class.
Comment #10
slashrsm commentedGreat job! Patch looks very good. I just have some (minor) comments.
My personal preference are higher numbers that have priority before the lower ones. It seems more natural to me. This being just my personal preference please take it just as a well-intentioned and optional comment.
Related to the previous comment. No matter which approach we take (lower-highest or high-lowest), it should be clearly documented here. It will prevent a lot of confusion.
As chx already mentioned on IRC we need to modify existing index.
You probably do not need this function here, as you already create this field in update_fix_d8_requirements().
Comment #11
tsphethean commentedslashrsm - thanks for your review and comments (and thanks to chx if he's following). I've uploaded a revised patch with the following changes:
thanks again for the review.
Comment #12
slashrsm commentedLooks good. I am just wondering if we could add just one index. If we'd put name on the first place in multi-column index there would be no need for single-column index on name. I was playing a bit with this idea and I think it could be achievable.
I was getting only "Using where" for query that loads new queue item for execution, which seems OK.
Comment #13
tsphethean commentedGood idea - I wasn't sure if that would work, but EXPLAIN looks ok and talking through with a few people it sounds a good approach.
Revised patch changes the order of keys in the combined index and removes the single column index on name.
Comment #14
slashrsm commentedLooks good to me. Great job!
Comment #15
webchickI asked msonnabaum to take a look at this patch. In the meantime, tagging as something that was RTBC in time for feature freeze.
Comment #16
msonnabaum commentedThis is not a feature we should include in the interface. Although it is supported by some queues, it's not supported by all (i.e. redis), which will make it very awkward to implement.
I've always solved this problem by putting high priority items in a dedicated queue, which works for most cases. If you need more than that, it can easily be solved in contrib.
Comment #17
tsphethean commentedIsn't that a decision to be made by the implementing Queue backend class about how to treat the priority, and if the queue doesn't support it then it ignores it. We already have queue features which arent supported by all backends (i.e. countItems() is not supported with any STOMP based queue backends, and Beanstalkd doesnt support createQueue or deleteQueue). By providing the option in the core classes which are able to support it we're providing more options for queue implementers?
Comment #18
catchYeah I've done the same.
I think we could remove that, calling code can track how much it's processed if it needs to, it's only used one place in core outside of tests.
It doesn't really need to though. There's a difference between methods that might be needed by certain backends to function properly - i.e. if they have to create a schema, vs. methods that just can't be supported meaningfully.
Comment #19
tsphethean commentedOk, fair enough. Will set this to won't fix then.
Comment #19.0
tsphethean commentedUpdated issue summary for more detail and to meet convention.