4

I have implemented the Queue API inside hook_cron, to do certain update operations on a site:

function HOOK_cron() {
  $interval = variable_get('variable_val', 60 * 60 * 24);
  if (time() >= variable_get('cron_next_execution', 0)) {
    variable_set('cron_next_execution', time() + $interval);
    $queue = 'MODULE_queue';
    $queue = DrupalQueue::get($queue);
    $query = db_query('SELECT nid FROM {node} WHERE type=:type', array(':type' => 'profile'))->fetchAll();
    foreach ($query as $node_obj) {
      $node = node_load($node_obj->nid);
      $queue->createItem($node);
    }
  }
}

where MODULE_queue is name of the queue, who's worker callback does some task on the nodes.

At any moment of time I would like the administrators to be able to run the updates manually using batch. I would like something like this

  • Check if there is anything pending in a queue at the moment Admin chooses to manually update, and execute them in batch.
  • If not just run a manual batch update.

So, I'm stuck at the part where I need to run the queue inside batch. I am not sure if this even is possible. Any pointers would be highly appreciated.

2
  • 1
    I would prefer to know "how?" over "is it possible?". I can bet it is, even if I don't exactly know how ;)
    – Mołot
    Commented Dec 9, 2013 at 8:38
  • @Mołot There's an answer just below, to answer how :)
    – AjitS
    Commented Dec 11, 2013 at 7:35

1 Answer 1

2

Check: https://drupal.org/project/queue_ui

Process queue with Batch API

2
  • I rolled back the edit previously made. There's no point in copying the project page; I have quoted the relevant feature.
    – user49
    Commented Dec 11, 2013 at 2:14
  • Also you'll require this patch to run system queues via Queue UI module - drupal.org/node/700836. Because by default it supports only its own queues.
    – m1r1k
    Commented Dec 11, 2013 at 8:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.