CoolCMS API

CronSchedulerManager
in package

FinalYes

Process of the cron scheduler: picks the enabled jobs that are due and calls them one by one over HTTP on the application's own address with the same token a hosting cron would use. Concurrency of two scheduler runs is stopped by the lock of the cron presenter; every job keeps its own lock too.

  • time budget BUDGET_SECONDS per run; each call may take what is left, and a job is not started with less than MIN_CALL_SECONDS left — it stays due for the next call;
  • jobs of a deactivated module (cms_system_modules.activated = 0) never run; the system module is always on;
  • the longest-waiting job goes first;
  • a job that failed or timed out is tried again only at its next term — the run time is stored whatever the outcome (except "skipped": another run of the job was in progress, retry next call).

The "run time" of a job is the start of the scheduler call that ran it, so consecutive terms of an interval job are exactly one scheduler tick apart whatever the jobs before it took.

Table of Contents

Constants

BUDGET_SECONDS  : int = 45
MIN_CALL_SECONDS  : int = 3
RUN_NOW_TIMEOUT_SECONDS  : int = 50

Properties

$catalog  : CronJobCatalog
$cronJobManager  : CronJobManager
$httpCaller  : CronJobHttpCaller

Methods

__construct()  : mixed
run()  : array{executed: int, failed: int, skipped: int, pending: int, durationMs: int, jobs: list}
One scheduler call: sync the catalog, run what is due within the budget, store the results.
runNow()  : Result
"Run now" from the administration: the same call, outside the schedule and regardless of the enabled switch (an explicit decision of the administrator). The run counts as the job's last run.
selectDue()  : array<int, array{id: int, path: string, frequency: string, enabled: bool, available: bool, moduleActive: bool, lastRunTime: string|null}>
Enabled, available jobs that are due at `$now`, the longest-waiting first (never-run first).
syncCatalog()  : int
Mirrors the code catalog into the table; returns the number of jobs in the catalog.
callJob()  : CronJobCallResult
storeResult()  : void

Constants

Properties

Methods

run()

One scheduler call: sync the catalog, run what is due within the budget, store the results.

public run(string $baseUrl, string $token, DateTimeImmutable $now) : array{executed: int, failed: int, skipped: int, pending: int, durationMs: int, jobs: list}
Parameters
$baseUrl : string
$token : string
$now : DateTimeImmutable
Return values
array{executed: int, failed: int, skipped: int, pending: int, durationMs: int, jobs: list}

runNow()

"Run now" from the administration: the same call, outside the schedule and regardless of the enabled switch (an explicit decision of the administrator). The run counts as the job's last run.

public runNow(int $id, string $baseUrl, string $token, DateTimeImmutable $now) : Result
Parameters
$id : int
$baseUrl : string
$token : string
$now : DateTimeImmutable
Return values
Result —

data: status (ok/error/skipped), httpCode, durationMs, response

selectDue()

Enabled, available jobs that are due at `$now`, the longest-waiting first (never-run first).

public static selectDue(array<int, array{id: int, path: string, frequency: string, enabled: bool, available: bool, moduleActive: bool, lastRunTime: string|null}> $rows, DateTimeImmutable $now) : array<int, array{id: int, path: string, frequency: string, enabled: bool, available: bool, moduleActive: bool, lastRunTime: string|null}>
Parameters
$rows : array<int, array{id: int, path: string, frequency: string, enabled: bool, available: bool, moduleActive: bool, lastRunTime: string|null}>
$now : DateTimeImmutable
Return values
array<int, array{id: int, path: string, frequency: string, enabled: bool, available: bool, moduleActive: bool, lastRunTime: string|null}>

syncCatalog()

Mirrors the code catalog into the table; returns the number of jobs in the catalog.

public syncCatalog() : int
Return values
int
On this page

Search results