@bight-ts/plugin-scheduler
import { createSchedulerPlugin, createStorageSchedulerStore, defineScheduledTask,} from "@bight-ts/plugin-scheduler";createSchedulerPlugin(options)
Section titled “createSchedulerPlugin(options)”Registers and manages persistent recurring tasks.
Options
Section titled “Options”| Property | Type | Required | Description |
|---|---|---|---|
tasks | ScheduledTask[] | Yes | Array of task definitions |
store | (context) => SchedulerStore | No | Persistence backend. Without it, task timing resets on restart. |
enabled | boolean | No | Toggle the plugin |
name | string | No | Plugin name. Defaults to "scheduler" |
loggerScope | string | No | Logger scope. Defaults to "scheduler" |
defineScheduledTask(task)
Section titled “defineScheduledTask(task)”Defines a recurring task.
ScheduledTask<TServices>
Section titled “ScheduledTask<TServices>”| Property | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Unique task identifier |
intervalMs | number | Yes | Milliseconds between runs |
runOnStart | boolean | No | Run immediately on boot. Defaults to false |
run | (input: { context }) => void | Yes | Task handler |
createStorageSchedulerStore(storage)
Section titled “createStorageSchedulerStore(storage)”Creates a scheduler store backed by Bight’s storage facade. Persists task timestamps so the scheduler resumes from the correct point after a restart.
| Parameter | Type | Description |
|---|---|---|
storage | StorageContext | The storage facade from createStorage() |
Diagnostic events
Section titled “Diagnostic events”The scheduler emits these events to the diagnostics hub:
| Event | When |
|---|---|
task_scheduled | Task is queued with a computed nextRunAt |
task_started | Task begins execution |
task_succeeded | Task completes without error |
task_failed | Task throws (captured, does not crash the runtime) |