You are here

function feeds_cron in Feeds 8.3

Same name and namespace in other branches
  1. 8.2 feeds.module \feeds_cron()
  2. 6 feeds.module \feeds_cron()
  3. 7.2 feeds.module \feeds_cron()
  4. 7 feeds.module \feeds_cron()

Implements hook_cron().

File

./feeds.module, line 81
Feeds hook implementations.

Code

function feeds_cron() {
  $ids = \Drupal::entityQuery('feeds_feed')
    ->condition('queued', 0)
    ->condition('next', \Drupal::time()
    ->getRequestTime(), '<=')
    ->condition('next', -1, '<>')
    ->condition('status', 1)
    ->range(0, 100)
    ->sort('imported')
    ->execute();
  foreach (Feed::loadMultiple($ids) as $feed) {
    if (!$feed
      ->isLocked()) {
      $feed
        ->startCronImport();
    }
  }

  // Delete queued timestamp after 12 hours assuming the update has failed.
  $ids = \Drupal::entityQuery('feeds_feed')
    ->condition('queued', \Drupal::time()
    ->getRequestTime() - 3600 * 12, '<')
    ->execute();
  foreach (Feed::loadMultiple($ids) as $feed) {
    $feed
      ->setQueuedTime(0);
    $feed
      ->save();
  }
}