Repository navigation
v1.27.0
Cron: scheduled calls of API routes (APICronScheduler), see the README
section "Cron: scheduled routes".
APICronJob: a route called on a 5 fields cron expression
(CronExpression), in an IANA time zone (daylight saving aware).- Declared by
@APICronon a reflected route method, by
APIRoot.loadCronJobs(), or by thecron.jobsconfig (which can also
override or disable a job of the code by name). An invalid config entry,
or one for an unknown job, is skipped (logged): the other jobs run. timeout,maxLatenessandleaseDurationmust be positive, and
retry.attemptsat least 1. The time zone is resolved when the scheduler
starts (a job with an unknown one is skipped).@APICron('30 23 * * *', ...)takes a cron expression, and
@APICron.at(minute: '30', hour: '23', ...)the schedule by its fields
(minute,hour,dayOfMonth,month,dayOfWeek; default*).
Both acceptname,timeZone,parameters,enabled,maxCalls,
attempts,timeout,maxLateness,leaseDurationandretry.- Called through
APIRoot.call, with an internal system authentication
(APIAuthentication.system, passesAPIRouteAuthenticatedRule), the
requester sourceinternaland the headersX-Cron-Job,
X-Cron-Scheduled-At,X-Cron-RunandX-Cron-Attempt. - Continuation: while the response has the header
X-Continuation
(APIResponse.continuation), the route is called again with the
parametercontinuation, up tomaxCallsper run. - Retries (
APICronRetry): exponential backoff (default 3 attempts: 30s,
2m), honoringRetry-After(capped bymaxDelay).UNAUTHORIZED,
BAD_REQUESTandNOT_FOUNDare not retried. timeout: a slower call is logged, but waited for (a route can't be
cancelled): never retried or overlapped while running.
- Declared by
APICronScheduler: started when the configcron.enabled(or
cron: true) istrue, onceAPIRootand its modules are successfully
initialized (cronSchedulerReady); not in auxiliary worker isolates (one
per process). Acronconfig of another type is ignored (disabled), and
the scheduler never fails the API initialization. Stopped by
APIRoot.close: a running job stops after its current call (left
resumable, its lock released; seewaitRunning), and no other check or
runNowruns until started again.- Each occurrence runs once: its run is claimed in the
APICronStore
(unique job + scheduled time), also among several instances. - A job never runs in parallel: a lock with a lease, renewed while running
(and considered lost if the lease runs out unrenewed). An interrupted run
is resumed from its last continuation token by the next check: at once
after a graceful stop (lock released), or after the lease expires if its
instance died. A run is only written by its owner while running: an
instance that lost the lock writes nothing. - A run that fails by an error (or a continuation token over 4096
characters) is marked failed, never left running. - The leases use each instance's clock: keep the servers' clocks
synchronized (NTP). - Missed occurrences (servers down): the latest runs once if not older
thanmaxLateness(default 1 day); older ones are recorded as skipped
(at most the 100 after the last run, per check). runNow(job),selectRuns(job), and history pruning (history_days,
default 90; never a running run, nor a run still in its job's
maxLatenesswindow, that would run again).- Logged by the logger
APICron.
- Each occurrence runs once: its run is claimed in the
APICronStore:APICronStoreMemory(single instance) and
APICronStoreDB(tablesapi_cron_job_runandapi_cron_job_lock; add
APICronStoreDB.buildRepositories(adapter)to the repositories of the
API).APIRoot.loadCronStore()uses the DB store when its repositories
are registered (otherwise the in-memory store, with a warning: single
instance only).APIModule.cronJobsandaddCronJob(a duplicated job name in a module
is an error; an@APICronjob is only added with its route). Note: modules with generated
reflection (routes.anyFrom(reflection)) need the reflection code
regenerated (build_runner) to include the newcronJobsfield.- New dependency:
timezone.