introduction to cron queue
Post on 26-Jun-2015
106 Views
Preview:
DESCRIPTION
TRANSCRIPT
Introduction to Cron QueueOlga Smolyankina
300 FOR ALL
Elysia Cron
Ultimate Cron
cron.php
.crontab
Run methods
.crontabdrush queue-cronmodules/drupal_queue_cron.php
Usage cases
● Entity items creation.● Sending emails.● Other mass operations.
Usage cases
How To. Add Queue Items
$queue = DrupalQueue::get('queue_name');
$queue->createQueue();
$queue->createItem(array(
'key1' => $value1,
'key2' => $value2,
...
)); APIhook_cron()
hook_node_insert($node)
hook_user_insert(&$edit, $account, $category)
hook_commerce_cart_order_empty($order)
...
How To. Add Queue Items
API/**
* Implements hook_cronapi().
*/
function mymodule_queue_cronapi($op, $job = NULL) {
$items = array();
$items['add_queue_items'] = array(
'rule' => '0 5 * * *',
'arguments' => array(),
'callback' => 'add_queue_items_callback',
);
return $items;
}
● Elysia Cron
How To. Implementation/**
* Implements hook_cron_queue_info().
*/
function mymodule_cron_queue_info() {
$queues = array();
$queues['queue_name'] = array(
'worker callback' => '_mymodule_queue_worker_callback',
'time' => 90,
'skip on cron' => FALSE,
);
return $queues;
}
How To. Process Queue Itemssystem.queue.inc
DrupalQueueInterface::createQueue();
DrupalQueueInterface::deleteQueue();
DrupalQueueInterface::createItem($data);
DrupalQueueInterface::claimItem($lease_time = 3600);
DrupalQueueInterface::releaseItem($item);
DrupalQueueInterface::deleteItem($item);
DrupalQueueInterface::numberOfItems();
Queue Run Tracking
● Queue UI● Ultimate Cron
Negatives
Negatives vs Features
● Cron run frequency.
● Cron run duration.
● Cron run propriety.
● Item locking => single cron job at once.
● Queue decoupled from the code => external queue run!
Thank you!
top related