@mastra/core
Version:
50 lines • 2.08 kB
TypeScript
import { MastraBase } from '../../base.js';
import type { PubSub } from '../../events/pubsub.js';
import type { SchedulesStorage } from '../../storage/domains/schedules/base.js';
import type { SchedulerConfig } from './types.js';
export declare const TOPIC_AGENT_SCHEDULES = "agent-schedules";
/**
* 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 Scheduler extends MastraBase {
#private;
constructor({ schedulesStore, pubsub, config, }: {
schedulesStore: SchedulesStorage;
pubsub: PubSub;
config?: SchedulerConfig;
});
/** 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>;
}
/**
* @deprecated Renamed to {@link Scheduler}. The scheduler now drives both
* workflow and agent schedules, so the `Workflow`-prefixed name is no longer
* accurate. This alias will be removed in a future major release.
*/
export declare const WorkflowScheduler: typeof Scheduler;
/**
* @deprecated Renamed to {@link Scheduler}. This alias will be removed in a
* future major release.
*/
export type WorkflowScheduler = Scheduler;
//# sourceMappingURL=scheduler.d.ts.map