Mercurial > hg > cmmr2012-drupal-site
annotate vendor/chi-teck/drupal-code-generator/templates/d7/hook/cron.twig @ 0:c75dbcec494b
Initial commit from drush-created site
author | Chris Cannam |
---|---|
date | Thu, 05 Jul 2018 14:24:15 +0000 |
parents | |
children |
rev | line source |
---|---|
Chris@0 | 1 /** |
Chris@0 | 2 * Implements hook_cron(). |
Chris@0 | 3 */ |
Chris@0 | 4 function {{ machine_name }}_cron() { |
Chris@0 | 5 // Short-running operation example, not using a queue: |
Chris@0 | 6 // Delete all expired records since the last cron run. |
Chris@0 | 7 $expires = variable_get('mymodule_cron_last_run', REQUEST_TIME); |
Chris@0 | 8 db_delete('mymodule_table') |
Chris@0 | 9 ->condition('expires', $expires, '>=') |
Chris@0 | 10 ->execute(); |
Chris@0 | 11 variable_set('mymodule_cron_last_run', REQUEST_TIME); |
Chris@0 | 12 |
Chris@0 | 13 // Long-running operation example, leveraging a queue: |
Chris@0 | 14 // Fetch feeds from other sites. |
Chris@0 | 15 $result = db_query('SELECT * FROM {aggregator_feed} WHERE checked + refresh < :time AND refresh <> :never', array( |
Chris@0 | 16 ':time' => REQUEST_TIME, |
Chris@0 | 17 ':never' => AGGREGATOR_CLEAR_NEVER, |
Chris@0 | 18 )); |
Chris@0 | 19 $queue = DrupalQueue::get('aggregator_feeds'); |
Chris@0 | 20 foreach ($result as $feed) { |
Chris@0 | 21 $queue->createItem($feed); |
Chris@0 | 22 } |
Chris@0 | 23 } |