Skip to main content
Drupal is a registered trademark of Dries Buytaert
Release: OpenID Connect / OAuth client 3.0.0-alpha9 New alpha version released for module openid_connect (3.0.0-alpha9). Release: Timelinr 1.0.1 Minor update available for module timelinr (1.0.1). Usage Milestone: Simplify Module simplify crossed 10,000 active installs. Usage Milestone: Views Reference Filter Module entityreference_filter crossed 10,000 active installs. Usage Milestone: Dropdown Language Module dropdown_language crossed 10,000 active installs. Usage Milestone: Paragraphs Browser Module paragraphs_browser crossed 10,000 active installs. Usage Milestone: OpenAPI Module openapi crossed 10,000 active installs. Usage Milestone: Decoupled Router Module decoupled_router crossed 10,000 active installs. Usage Milestone: Time Field for Drupal 8+ Module time_field crossed 10,000 active installs. Module Revived: Entityqueue Buttons 1.1.2 Module entityqueue_buttons updated after 8 months of inactivity (1.1.2).

Cron Service

102 sites Security covered Drupal 10–11
View on drupal.org

This module allows developers to run custom PHP code during Drupal's cron jobs by defining services with specific tags. It provides interfaces for creating tasks that execute on every cron run, or tasks that can be scheduled or conditionally run based on custom logic.

The module provides a service collector which executes tagged services on each hook_cron() and allows developers to not write any code to *.module file and have simple time controlling functionality.

The module doesn't have any configurations or UI. It's created for developers and only developers will decide how they will control the execution of their services.

To use the module developer must create a class which implementing \Drupal\cron_service\CronTaskInterface interface (or its descendant) and define it as a service with tag 'cron_service'.

The module provides the following interfaces:
\Drupal\cron_service\CronTaskInterface declares only execute() method which must be the entry point of desired logic. This method will be invoked on every cron run.

\Drupal\cron_service\ScheduledCronTaskInterface additionally declares getNextExecutionTime():int method which should return the timestamp when execute() method should be executed next time. 

\Drupal\cron_service\TimeControllingCronTaskInterface additionally declares shouldRunNow():bool method which is called before every call to execute()  and can prevent the execution by returning FALSE. It can contain additional checks of the current time or the current environment.

A small note

Despite the fact the project is marked as completed, I'm still opened for ideas. Feel free to add feature requests to the issues list if you think this module can be improved in any way.

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
Aug 2025
Latest release
6 months ago
Releases (12 mo)
1
Maintenance
Active

Releases

Version Type Core Release date
2.0.5 Stable 10–11 Feb 10, 2026
2.0.4 Stable 10–11 Aug 1, 2025