Chris@0: /** Chris@0: * Implements hook_cron(). Chris@0: */ Chris@0: function {{ machine_name }}_cron() { Chris@0: // Short-running operation example, not using a queue: Chris@0: // Delete all expired records since the last cron run. Chris@0: $expires = variable_get('mymodule_cron_last_run', REQUEST_TIME); Chris@0: db_delete('mymodule_table') Chris@0: ->condition('expires', $expires, '>=') Chris@0: ->execute(); Chris@0: variable_set('mymodule_cron_last_run', REQUEST_TIME); Chris@0: Chris@0: // Long-running operation example, leveraging a queue: Chris@0: // Fetch feeds from other sites. Chris@0: $result = db_query('SELECT * FROM {aggregator_feed} WHERE checked + refresh < :time AND refresh <> :never', array( Chris@0: ':time' => REQUEST_TIME, Chris@0: ':never' => AGGREGATOR_CLEAR_NEVER, Chris@0: )); Chris@0: $queue = DrupalQueue::get('aggregator_feeds'); Chris@0: foreach ($result as $feed) { Chris@0: $queue->createItem($feed); Chris@0: } Chris@0: }