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.