Automation and cron
What runs when, and how to hang your own background work on the same cron job instead of adding another.
One entry point#
All automation starts from cron.php, run every five minutes by a cron job or a web cron. Each run decides which tasks are due: frequent tasks every time or every few minutes, hourly ones once an hour, and the daily run once a day at the hour set under Automation Settings.
Running tasks yourself#
Every task can be run by hand from Utilities > Automation Status, and from the shell with the command line tools; see the command line page for the list.
Your own background work#
An add-on module listens to the tick event, which fires on every cron run. Keep each tick short: do a batch of queued work and leave the rest for the next one. A module that needs a schedule of its own keeps the time of its last run in its settings with saveConf() and checks it in tick.
public function events(): array
{
return ['tick' => 'onTick'];
}
public function onTick(array $data): void
{
if ((int) $this->conf('last_sync', 0) > time() - 3600) {
return; // hourly
}
// ... sync a batch ...
$this->saveConf(['last_sync' => time()]);
}Reacting to changes#
For work that follows a change, such as telling another system that a client changed their email, listen to the matching event (client.updated, invoice.created and so on) and queue the work for tick. See hooks and events.
Calling CoreInto from outside#
Systems outside CoreInto use the API with a credential limited to the scopes they need.