Since the queue system was introduced to Drupal 7, a slightly different version has emerged over in contrib land. This convention uses hook_queue_info(), thus decoupling the concept of queues from the idea that cron should run them. The idea is that for many tasks, cron just doesn't hold up as a viable queue runner, and shouldn't know or care about certain queues.
The waiting queue, queue ui and beanstalkd modules are all aware of hook_queue_info().
I propose the new hook look something like this:
function hook_queue_info() {
$queues['aggregator_feeds'] = array(
'title' => t('Aggregator refresh'),
'worker callback' => 'aggregator_refresh',
// Optional, if queue should be run by cron.
'cron' => array(
'time' => 60,
),
);
return $queues;
}
Comment | File | Size | Author |
---|---|---|---|
#8 | drupal-hook-queue-info-1509996-08.patch | 5.11 KB | jhedstrom |
#1 | drupal-hook-queue-info-1509996-01.patch | 4.67 KB | jhedstrom |
drupal-hook-queue-info.patch | 4.08 KB | jhedstrom | |
Comments
Comment #1
jhedstromThis patch updates the docblock as well.
Comment #2
msonnabaum CreditAttribution: msonnabaum commentedYes yes yes.
The queue runner in drush 5 is aware of hook_queue_info as well, because we absolutely need a way to declare queues that aren't automatically run in cron.
There is still room for improvement for this hook and the queue system in general for D8, but this is a solid, simple, incremental improvement. Looks great to me.
Comment #3
chx CreditAttribution: chx commentedNo no no. I will only consent to this patch if the API docs are amended to stress that you can use a queue without this queue just then it's your responsibility to run it. The ad-hoc queue ability is important to me.
Comment #4
msonnabaum CreditAttribution: msonnabaum commentedI have no idea what you're trying to say.
Comment #5
jhedstrom@chx it seems like the major concern here is that sloppy contrib modules may fail to implement the hook in such a way that allows sites without special queue-runners to properly process the queues? A more verbose API doc (wording suggestions welcome) may help a little with this, and also perhaps an implementation of hook_requirements that warns of queues without cron set?
Comment #6
chx CreditAttribution: chx commentedOK that got out a bit garbled. "if the API docs are amended to stress that you can use a queue without this hook" that's what I wanted to say. I mean if you want to operate on a queue it's not mandatory to put it in hook_queue_info. But if the queue is not in there, Drupal won't run it for you. If you write a custom runner then it'll work.
In other words, what I care about is that I be able to create a queue and put items in it without the hook defining it.
Comment #7
coltraneYou can create a queue, add items, and get items without having to use hook_cron_queue_info(), this patch doesn't change that ability. Queue UI invokes hook_queue_info() because it needs meta-data about queues without letting cron automatically process them as hook_cron_queue_info() would.
"implementation of hook_requirements that warns of queues without cron set" sounds like unnecessary hand-holding to me, developers using this hook should should read the API documentation and if there queue isn't being processed they'll figure it out.
Comment #8
jhedstromHere's a patch with the additional text added to the API doc that notes developers can manage queues without this hook from a conversation in IRC with chx and msonnabaum.
Comment #9
bojanz CreditAttribution: bojanz commentedPatch looks good to me. +1
Comment #10
chx CreditAttribution: chx commentedThat's all I asked. I tend to drop things in queues that can not be processed by any generic runner or be be processed by another drupal or even another system that's not Drupal. So that's why I wanted to clarify this.
Comment #11
catchMakes sense to me. Committed/pushed to 8.x, will need a change notification.
Comment #12
jhedstromAdded a change notice: http://drupal.org/node/1537256
Not sure the review process on these, so leaving open for now.
Comment #13
Niklas Fiekas CreditAttribution: Niklas Fiekas commentedThe change notification looks good and has a code example. Thank you jhedstrom!