Drupal is a registered trademark of Dries Buytaert
Protected Pages 3.0.0 Major update available for module protected_pages (3.0.0). Commerce Core 3.3.8 Minor update available for module commerce (3.3.8). Search API HTML Element Filter 1.0.7 Minor update available for module search_api_html_element_filter (1.0.7). Layout Builder Reorder 2.0.1 Minor update available for module layout_builder_reorder (2.0.1). Ban 1.1.0 Minor update available for module ban (1.1.0). Field Formatter Range 2.0.0 Major update available for module field_formatter_range (2.0.0). Field Formatter Range 8.x-1.8 Minor update available for module field_formatter_range (8.x-1.8). Varbase Media Header 9.2.1 Minor update available for module varbase_media_header (9.2.1). Search API Solr 4.3.11 Module search_api_solr updated after 14 months of inactivity (4.3.11). Provus Mega Menu Module provus_mega_menu crossed 1,000 active installs.

Cron Service

102 sites Security covered
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.

Activity

Total releases
2
First release
Aug 2025
Latest release
5 months ago
Releases (12 mo)
2 ▲ from 0
Maintenance
Active

Releases

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