16
Introduction to Cron Queue Olga Smolyankina

Introduction to cron queue

Embed Size (px)

DESCRIPTION

Introduction to cron queue

Citation preview

Page 1: Introduction to cron queue

Introduction to Cron QueueOlga Smolyankina

Page 2: Introduction to cron queue

300 FOR ALL

Page 3: Introduction to cron queue
Page 4: Introduction to cron queue
Page 5: Introduction to cron queue
Page 6: Introduction to cron queue

Elysia Cron

Ultimate Cron

cron.php

.crontab

Run methods

.crontabdrush queue-cronmodules/drupal_queue_cron.php

Page 7: Introduction to cron queue

Usage cases

● Entity items creation.● Sending emails.● Other mass operations.

Page 8: Introduction to cron queue

Usage cases

Page 9: Introduction to cron queue

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)

...

Page 10: Introduction to cron queue

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

Page 11: Introduction to cron queue

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;

}

Page 12: Introduction to cron queue

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();

Page 13: Introduction to cron queue

Queue Run Tracking

● Queue UI● Ultimate Cron

Page 14: Introduction to cron queue

Negatives

Page 15: Introduction to cron queue

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!

Page 16: Introduction to cron queue

Thank you!