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;
}

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jhedstrom’s picture

This patch updates the docblock as well.

msonnabaum’s picture

Status: Needs review » Reviewed & tested by the community

Yes 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.

chx’s picture

Status: Reviewed & tested by the community » Needs work

No 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.

msonnabaum’s picture

I have no idea what you're trying to say.

jhedstrom’s picture

@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?

chx’s picture

OK 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.

coltrane’s picture

Status: Needs work » Needs review

You 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.

jhedstrom’s picture

Here'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.

bojanz’s picture

Patch looks good to me. +1

chx’s picture

Status: Needs review » Reviewed & tested by the community

That'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.

catch’s picture

Title: Convert hook_cron_queue_info() to hook_queue_info() » Change notification for: Convert hook_cron_queue_info() to hook_queue_info()
Category: feature » task
Priority: Normal » Critical
Status: Reviewed & tested by the community » Active
Issue tags: +API change

Makes sense to me. Committed/pushed to 8.x, will need a change notification.

jhedstrom’s picture

Status: Active » Needs review

Added a change notice: http://drupal.org/node/1537256

Not sure the review process on these, so leaving open for now.

Niklas Fiekas’s picture

Title: Change notification for: Convert hook_cron_queue_info() to hook_queue_info() » Convert hook_cron_queue_info() to hook_queue_info()
Category: task » feature
Priority: Critical » Normal
Status: Needs review » Fixed

The change notification looks good and has a code example. Thank you jhedstrom!

Automatically closed -- issue fixed for 2 weeks with no activity.