UNPKG

@mastra/core

Version:

Mastra is a framework for building AI-powered applications and agents with a modern TypeScript stack.

38 lines 1.6 kB
import { MastraBase } from '../../base.js'; import type { PubSub } from '../../events/pubsub.js'; import type { SchedulesStorage } from '../../storage/domains/schedules/base.js'; import type { WorkflowSchedulerConfig } from './types.js'; /** * Drives cron-based workflow triggers. * * On each tick the scheduler: * 1. Loads schedules whose `nextFireAt <= now` from storage. * 2. Computes the next fire time from the cron expression. * 3. Atomically advances `nextFireAt` via compare-and-swap. Only one * instance across many polling the same storage can claim a fire. * 4. Publishes a `workflow.start` event on the `workflows` pubsub topic. * 5. Records the trigger in the schedule's history. * * The scheduler does **not** execute workflows. The existing * `WorkflowEventProcessor` consumes `workflow.start` events and runs them. */ export declare class WorkflowScheduler extends MastraBase { #private; constructor({ schedulesStore, pubsub, config, }: { schedulesStore: SchedulesStorage; pubsub: PubSub; config?: WorkflowSchedulerConfig; }); /** Start the periodic tick loop. Runs an immediate tick first. */ start(): Promise<void>; /** Stop the tick loop and wait for any in-flight tick to finish. */ stop(): Promise<void>; /** True when the scheduler is currently running its tick loop. */ get isRunning(): boolean; /** * Run a single tick. Public for tests; production callers should rely * on the interval started by `start()`. */ tick(): Promise<void>; } //# sourceMappingURL=scheduler.d.ts.map