ECA cron event¶
Available since: 1.0.0
Provided tokens
| Token | Description |
|---|---|
[event] |
The event. |
[event:machine_name] |
The machine name of the ECA event. |
[session_user] |
The user account that dispatched the event, regardless if ECA is processing models under a different account. This is only available if ECA is configured to always run under a specific account. |
This event reacts to Drupal's cron system and allows you to schedule ECA processes at specific intervals.
How it works¶
Drupal core provides a cron API that all modules can hook into. When cron runs, core asks every registered module — including ECA — whether it has work to do. ECA then checks the Frequency field of each cron event in your models to determine whether that particular event is due for execution. If it is, the model's actions are processed; otherwise, the event is skipped.
This means:
- System-level cron must run first. The ECA cron event does not trigger
itself — it only fires when Drupal's cron runs. On production sites, it is
strongly recommended to disable the
automated_cronmodule and instead rundrush cronfrom a system-level crontab (e.g. every minute or at least every 5 minutes). - The Frequency field is a schedule filter, not a trigger. Setting a
frequency of
0 1 * * 1(every Sunday at 1:00 UTC) does not cause ECA to run at that time by itself. It tells ECA to only execute this event when cron happens to run at or after the scheduled time. The more frequently your system cron runs, the more precisely ECA can honor the frequency you define. - Cron runs as the anonymous user. Unless configured otherwise, cron processes run without an authenticated session. If your actions require specific permissions (e.g. querying a view with access restrictions), add a User: switch current account action immediately after this event to switch to an account with the necessary permissions.
Avoid rendering actions in cron context
Actions that render HTML (such as rendering a view) may fail during cron because there is no active HTTP session. You might see errors like "Failed to start the session because headers have already been sent". Consider using non-rendering alternatives or ensure your model accounts for the headless cron context.
Fields¶
Frequency-
The frequency of a cron job is defined by a cron specific notation which is best explained at https://en.wikipedia.org/wiki/Cron. Note: date and time need to be provided in UTC timezone.
This field defines when the ECA cron event should be considered due for execution. It does not control when Drupal's system cron runs — that is configured separately at the server or Drupal level.
Each time system cron runs, ECA evaluates this frequency expression to decide whether the event should fire. If the current time matches the schedule, the event's actions are executed; otherwise, the event is skipped until the next cron run.
Examples:
| Expression | Meaning |
|---|---|
* * * * * |
Every time cron runs (effectively every minute if system cron runs every minute) |
0 */1 * * * |
Once per hour, at the top of the hour |
0 2 * * * |
Daily at 02:00 UTC |
0 1 * * 1 |
Every Monday at 01:00 UTC |
0 0 1 * * |
First day of every month at midnight UTC |
Precision depends on system cron frequency
If your system cron runs only every 15 minutes, an ECA frequency of
*/5 * * * * (every 5 minutes) will not actually fire every 5 minutes.
ECA can only evaluate the schedule when cron runs, so the effective
precision is limited by how often system cron is triggered.