function AnnouncementsFeedHooks::cron

Implements hook_cron().

File

core/modules/announcements_feed/src/Hook/AnnouncementsFeedHooks.php, line 125

Class

AnnouncementsFeedHooks
Hook implementations for announcements_feed.

Namespace

Drupal\announcements_feed\Hook

Code

public function cron() : void {
    $config = \Drupal::config('announcements_feed.settings');
    $interval = $config->get('cron_interval');
    $last_check = \Drupal::state()->get('announcements_feed.last_fetch', 0);
    $time = \Drupal::time()->getRequestTime();
    if ($time - $last_check > $interval) {
        \Drupal::service('announcements_feed.fetcher')->fetch(TRUE);
        \Drupal::state()->set('announcements_feed.last_fetch', $time);
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.