mob_queue.api.php in Drush Queue Handling 7
Same filename and directory in other branches
Hooks provided by the Drush Queue Handling module.
File
mob_queue.api.phpView source
<?php
/**
* @file
* Hooks provided by the Drush Queue Handling module.
*/
/**
* @addtogroup hooks
* @{
*/
/**
* Alter cron queue information before mob-queue runs.
*
* Called by mob-queue to allow modules to alter cron queue
* settings before any jobs are processesed.
* It works the same as hook_cron_queue_info() but this
* hook applies only to mob-queue, in case you want to alter
* queues only under mob-queue execution.
*
* @param array $queue
* An array of cron queue information.
*
* @see hook_cron_queue_info_alter()
*/
function hook_mob_queue_cron_queue_info_alter(&$queues) {
// Remove this queue from mob-queue's queue list at all.
unset($queues['myqueue']);
}
/**
* Alter queue information while mob-queue is running.
*
* Allows to alter the queue list and next-to-be-processed
* queue information.
* Caution: Make sure you understand how mob-queue works internally.
* Most of the time, you should alter the $queue_name and $queue_info
* variables in sync.
* However, you can change the queue name parameter independent from
* its info array and wreak havoc.
*
* @param string $queue_name
* The queue name.
* @param array $queue_info
* The queue information array item as declared in the queue's
* hook_cron_queue_info().
* @param array $queues
* An array of cron queue information.
*
* @see hook_cron_queue_info()
*/
function hook_mob_queue_queue_processing_alter(&$queue_name, &$queue_info, &$queues) {
$some_priority_condition = TRUE;
$a_more_important_queue = 'important-queue';
if ($some_priority_condition) {
$queue_name = $a_more_important_queue;
$info = $queues[$a_more_important_queue];
}
}
/**
* A queue item is about to be requested from a queue for processing.
*
* Modules may skip the queue processing by returning FALSE.
*
* @param string $queue_name
* The queue name.
* @param array $queue_info
* The queue information array item as declared in the queue's
* hook_cron_queue_info().
* @see hook_cron_queue_info()
*
* @return
* FALSE if queue processing should be skipped.
*/
function hook_mob_queue_queue_item_processing($queue_name, $queue_info) {
if ($queue_name == 'do_not_process') {
return FALSE;
}
}
/**
* A queue item has been processed.
*
* Modules are notified after an item has been processed.
* If the item processing failed (the worker function raised an exception),
* the $exception parameter will be the raised Exception object.
*
* @param string $queue_name
* The queue name.
* @param $item
* The processed item object.
* @see DrupalQueueInterface::claimItem
* @param $exception
* If the item's processing failed, the Exception object.
* Otherwise, it will be NULL.
*/
function hook_mob_queue_queue_item_processed($queue_name, $item, $exception) {
$watchdog_vars = array(
'@item-id' => $item->item_id,
'@queue-name' => $queue_name,
);
if (is_null($exception)) {
$msg = 'Successfully processed item @item-id from @queue-name queue.';
$severity = WATCHDOG_INFO;
}
else {
$msg = 'Item @item-id from @queue-name queue raised an exception: @exception-message';
$severity = WATCHDOG_ERROR;
$watchdog_vars['@exception-message'] = $exception
->getMessage();
}
watchdog('mymodule', $msg, $watchdog_vars, $severity);
}
/**
* A queue has been processed.
*
* @param string $queue_name
* The queue name.
* @param array $queue_info
* The queue information array item as declared in the queue's
* hook_cron_queue_info().
* @param array $queues
* An array of cron queue information.
*
* @see hook_cron_queue_info()
*/
function hook_mob_queue_queue_processed($queue_name, $info, $queues) {
watchdog('mymodule', 'Queue @queue has been processed.', array(
'@queue' => $queue_name,
));
}
/**
* @} End of "addtogroup hooks".
*/
Functions
Name![]() |
Description |
---|---|
hook_mob_queue_cron_queue_info_alter | Alter cron queue information before mob-queue runs. |
hook_mob_queue_queue_item_processed | A queue item has been processed. |
hook_mob_queue_queue_item_processing | A queue item is about to be requested from a queue for processing. |
hook_mob_queue_queue_processed | A queue has been processed. |
hook_mob_queue_queue_processing_alter | Alter queue information while mob-queue is running. |