APICronScheduler class
Calls the routes of the APICronJobs of an APIRoot on their schedules.
- Each occurrence runs once: its run is claimed in the store (APICronStore.claimRun), also among several instances of the API.
- A job never runs in parallel: its lock (APICronStore.acquireLock) is held (and renewed) while running. A run interrupted (the instance stopped) is resumed by any instance after its lock lease expires, from its last continuation token.
- A missed occurrence (the servers were down) runs once if not older than APICronJob.maxLateness; older ones between the last run and it are recorded as APICronRunStatus.skipped.
- The calls follow the
X-Continuationheader (APIResponse.continuation) and are retried by APICronJob.retry.
Started by APIRoot when the config cron.enabled is true (see
APICronConfig); one scheduler per process (not in the auxiliary
workers).
Constructors
-
APICronScheduler(APIRoot apiRoot, Iterable<
APICronJob> jobs, {APICronStore? store, Duration checkInterval = const Duration(seconds: 30), int historyDays = 90, String? owner, DateTime clock()?, Future<void> sleep(Duration delay)?})
Properties
- apiRoot → APIRoot
-
final
- checkInterval → Duration
-
How often the due jobs are checked.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- historyDays → int
-
The days the run history is kept (
0: forever).final - isStarted → bool
-
no setter
-
jobs
→ Map<
String, APICronJob> -
The jobs, by name.
no setter
- owner → String
-
The ID of this scheduler instance (the owner of its runs and locks).
final
-
runningJobs
→ Set<
String> -
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- store → APICronStore
-
final
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
runNow(
String name) → Future< APICronJobRun?> -
Runs the job
namenow (an occurrence at the current time), with the same lock and claim of a scheduled run.nullif already running, locked by another instance or this scheduler is stopped (stop). Throws an ArgumentError for an unknown job. -
selectRuns(
String name, {int limit = 20}) → FutureOr< List< APICronJobRun> > -
The latest runs of the job
name. -
start(
) → void - Starts the periodic checks (and checks once now).
-
stop(
) → void -
Stops the periodic checks. A running job stops after its current call
(not cancelled): its run is left
runningand its lock released, so another instance resumes it from its continuation. See waitRunning. -
tick(
) → Future< List< APICronJobRun> > - Checks the due jobs and runs them. Completes when the runs started by this check finish (with their runs).
-
toString(
) → String -
A string representation of this object.
override
-
waitRunning(
) → Future< void> - Waits for the jobs running in this instance (e.g. after stop).
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
mergeJobs(
Iterable< Iterable< sources, Map<APICronJob> >String, Map> config) → List<APICronJob> -
Merges the jobs of
sources(by name: a later job replaces an earlier one) and appliesconfig(thecron.jobsconfig): a config entry overrides the job of its name, or adds a new job (withscheduleandpath).
Constants
- maxSkippedRecords → const int
- The maximum missed occurrences recorded as skipped per check.