Runs check groups on a schedule.
A scheduler entry pairs a schedule with a Botica.Check.Group (or any
zero-arity runner function). The scheduler fires the group, stores the
result in a bounded ETS history, and optionally notifies a subscriber
after every run.
Schedules
Two forms are supported:
every: {:minutes, N}/{:seconds, N}/{:milliseconds, N}— fixed interval.cron: "*/5 * * * *"— a 5-field cron expression (minute hour day-of-month month day-of-week). Only*and*/Nsteps are supported in the first field; other fields must be*.
Example
group = Botica.Check.Group.new(:db, [check_db], timeout_ms: 2_000)
:ok = Botica.Scheduler.add(:db_every_5m, group, every: {:minutes, 5})
:ok = Botica.Scheduler.add(:db_at_night, group, cron: "*/5 * * * *")History
The last max_history results per schedule are kept in a private ETS
table (default 10). Query with history/1.
Summary
Functions
Registers a scheduled run.
Returns all registered schedules (name → schedule spec).
Returns a specification to start this module under a supervisor.
Returns the last max_history results for a schedule (most recent first).
Removes a scheduled run.
Manually triggers a schedule now (useful for tests and on-demand runs).
Functions
@spec add(atom(), Botica.Check.Group.t() | (-> term()), keyword()) :: :ok | {:error, term()}
Registers a scheduled run.
Options
:every—{:milliseconds, n}|{:seconds, n}|{:minutes, n}:cron— cron expression (5 fields,*/*/Nin minute field):runner— zero-arity fun (defaults tofn -> Group.run(group) end):max_history— history entries kept (default 10):notify—fun.({:ok, results}) | ({:error, reason})after each run
Exactly one of :every / :cron must be provided.
Returns all registered schedules (name → schedule spec).
Returns a specification to start this module under a supervisor.
See Supervisor.
Returns the last max_history results for a schedule (most recent first).
@spec remove(atom()) :: :ok
Removes a scheduled run.
@spec run_now(atom()) :: :ok | {:error, :not_found}
Manually triggers a schedule now (useful for tests and on-demand runs).