Skip to main content
drupalreleases

Use direct release data with your AI assistant.

Learn more

Periodic

Security covered Under active development 1 sites

This module provides a utility for throttling the execution of tasks. It emits events for hourly, daily, weekly, and monthly intervals that can be subscribed to, and allows for custom tasks to be throttled by arbitrary intervals.

Utility for throttling execution of tasks.

Scheduled Tasks

The module emits events for hourly, daily, weekly, and monthly intervals that can be subscribed to.

MyModuleEventSubscriber {

  public static function getSubscribedEvents() {
    $events = [];

    $events[PeriodicEvents::HOUR] = ['hourlyTask'];
    $events[PeriodicEvents::DAY] = ['dailyTask'];

    return $events;
  }

  public function hourlyTask() {
    // Do hourly task.
  }

  public function dailyTask() {
    // Do daily task.
  }

}

Note: These events are triggered by cron, so will execute on the next cron run following the interval's expiry.

Custom Tasks

Custom tasks can be throttled by arbitrary intervals.

function mymodule_cron() {
  $periodManager = \Drupal::service('periodic.manager');

  // Limit task to every six hours.
  if ($periodManager->execute('mymodule.mytask', 21600)) {
    // Do custom task.
  }

  // Delay first execution of a task.
  if ($periodManager->execute('mymodule.mydelayedtask', 21600, FALSE)) {
    // Do custom task.
  }
}
Drupal 9–10 · not 11 PHP ^7.2 || ^8.0

Ask your assistant about Periodic

Check compatibility with your Drupal and PHP version, maintenance and security coverage, from current release data. How it works

Depends on

Dependencies of the latest stable release

No dependencies recorded for this project.

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
2
Tracked since
Mar 2023
Latest release
3 years ago
Releases (12 mo)
0
Maintenance
Dormant

Releases

Version Type Core PHP Release date
1.x-dev Dev 9–10 PHP ^7.2 || ^8.0 Mar 8, 2023
1.2.0 Stable 9–10 PHP ^7.2 || ^8.0 Mar 8, 2023