2 * Implements hook_cron().
4 function {{ machine_name }}_cron() {
5 // Short-running operation example, not using a queue:
6 // Delete all expired records since the last cron run.
7 $expires = variable_get('mymodule_cron_last_run', REQUEST_TIME);
8 db_delete('mymodule_table')
9 ->condition('expires', $expires, '>=')
11 variable_set('mymodule_cron_last_run', REQUEST_TIME);
13 // Long-running operation example, leveraging a queue:
14 // Fetch feeds from other sites.
15 $result = db_query('SELECT * FROM {aggregator_feed} WHERE checked + refresh < :time AND refresh <> :never', array(
16 ':time' => REQUEST_TIME,
17 ':never' => AGGREGATOR_CLEAR_NEVER,
19 $queue = DrupalQueue::get('aggregator_feeds');
20 foreach ($result as $feed) {
21 $queue->createItem($feed);