Skip to content

@bight-ts/plugin-scheduler

import {
createSchedulerPlugin,
createStorageSchedulerStore,
defineScheduledTask,
} from "@bight-ts/plugin-scheduler";

Registers and manages persistent recurring tasks.

PropertyTypeRequiredDescription
tasksScheduledTask[]YesArray of task definitions
store(context) => SchedulerStoreNoPersistence backend. Without it, task timing resets on restart.
enabledbooleanNoToggle the plugin
namestringNoPlugin name. Defaults to "scheduler"
loggerScopestringNoLogger scope. Defaults to "scheduler"

Defines a recurring task.

PropertyTypeRequiredDescription
namestringYesUnique task identifier
intervalMsnumberYesMilliseconds between runs
runOnStartbooleanNoRun immediately on boot. Defaults to false
run(input: { context }) => voidYesTask handler

Creates a scheduler store backed by Bight’s storage facade. Persists task timestamps so the scheduler resumes from the correct point after a restart.

ParameterTypeDescription
storageStorageContextThe storage facade from createStorage()

The scheduler emits these events to the diagnostics hub:

EventWhen
task_scheduledTask is queued with a computed nextRunAt
task_startedTask begins execution
task_succeededTask completes without error
task_failedTask throws (captured, does not crash the runtime)