SchedulerService class

Runs Schedules exactly once per time across the instances of an application. Built into ApplicationHost and TestHost, configured under scheduler.

To provide Exactly-once-globally, the following components are required:

  • a DataRepository<ScheduleRecord>: an instance claims a run by moving the next run time of the schedule's record with a conditional update, which only one instance can do,
  • a LockProvider<String>, so a run never overlaps with the previous run on another instance (lock schedule:<name>).

Without them, schedules run on every instance.

Missed runs (while no instance was running) are made up for with one run. Runs are not retried, the next time runs as usual.

Spans are named Schedule <name>, logs and spans carry datahub.scheduler.schedule. Metrics: <metricPrefix>_runs_total (schedule, outcome), <metricPrefix>_run_duration_seconds and <metricPrefix>_lateness_seconds (schedule).

Implemented types

Constructors

SchedulerService({Find<Telemetry> telemetry = const Find(), Find<DataRepository<ScheduleRecord>?> recordRepository = const Find(), Find<LockProvider<String>?> lockProvider = const Find(), Config<bool> worker = const Config('scheduler.worker', defaultValue: true), Config<Duration> pollInterval = const Config('scheduler.pollInterval', defaultValue: Duration(seconds: 10)), Config<bool> enableMetrics = const Config('scheduler.enableMetrics', defaultValue: true), Config<bool> enableTracing = const Config('scheduler.enableTracing', defaultValue: true), Config<String> metricPrefix = const Config('scheduler.metricPrefix', defaultValue: 'scheduler')})
const

Properties

enableMetrics → Config<bool>
final
enableTracing → Config<bool>
final
hashCode → int
The hash code for this object.
no setterinherited
lockProvider → Find<LockProvider<String>?>
final
metricPrefix → Config<String>
final
pollInterval → Config<Duration>
Time between two checks of the schedules, for changes made by other instances. Runs themselves start at their time.
final
recordRepository → Find<DataRepository<ScheduleRecord>?>
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
telemetry → Find<Telemetry>
final
worker → Config<bool>
Whether this instance runs schedules.
final

Methods

createInstance() → ServiceInstance<SchedulerService>
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited