The core fires maintenance events on a schedule, on the first request after each period:
| Event | When |
|---|---|
daily_maintenance |
Once a day, after midnight server time |
hourly_maintenance |
Once an hour |
ten_minute_maintenance |
Every 10 minutes |
minute_maintenance |
Once a minute |
Modules listen for them to do regular jobs: DB and System Backup makes its daily backup, and Site Builder its daily layout backup.
function xxFoo_init()
{
jrCore_register_event_listener('jrCore', 'daily_maintenance', 'xxFoo_daily_maintenance_listener');
return true;
}
function xxFoo_daily_maintenance_listener($_data, $_user, $_conf, $_args, $event)
{
// e.g. delete log entries older than 30 days
$tbl = jrCore_db_table_name('xxFoo', 'log');
jrCore_db_query("DELETE FROM {$tbl} WHERE log_time < " . (time() - (30 * 86400)));
return $_data;
}The listener runs during a visitor's request, so keep it short. For long jobs, create queue entries in the listener: see The Queue System.
Daily maintenance runs are logged in the Activity Log ("daily maintenance worker started" and "completed").