import type { Kysely } from 'kysely';
import type { Database } from '../db/types.js';
import type { RegistrationIndex } from '../registration/registration-index.js';
import type { EventRouter } from '../events/event-router.js';
import type { CronStore } from './cron-store.js';
interface CronSchedulerOptions {
    db: Kysely<Database>;
    registrationIndex: RegistrationIndex;
    cronStore: CronStore;
    eventRouter: EventRouter;
    evaluationIntervalMs?: number;
}
/**
 * Raft-leader-only cron evaluator.
 *
 * Only the current Raft leader evaluates cron schedules. On becoming leader,
 * loads the last-fired cache from the DB, recovers missed schedules (fires
 * once per schedule), then starts periodic evaluation.
 *
 * On losing leadership, stops evaluation immediately.
 *
 * Atomicity: each fire wraps `cronStore.tryClaimFire` and
 * `eventRouter.emitInTx` in a single Postgres transaction. `pg_notify`
 * inside that tx is queued by Postgres until commit, so a rollback discards
 * both the `cron_last_fired` write AND the listener notification together.
 * This closes the previous silent-loss window where a crash between claim
 * and emit advanced `last_fired_at` without persisting an event row.
 */
export declare class CronScheduler {
    private readonly db;
    private readonly registrationIndex;
    private readonly cronStore;
    private readonly eventRouter;
    private readonly evaluationIntervalMs;
    private timer;
    private isLeader;
    private lastFiredCache;
    constructor(options: CronSchedulerOptions);
    /**
     * Called when this orchestrator becomes the Raft leader.
     * Loads last-fired cache, recovers missed schedules, starts periodic evaluation.
     */
    onBecomeLeader(): Promise<void>;
    /**
     * Called when this orchestrator loses Raft leadership.
     * Stops the evaluation timer immediately.
     */
    onLoseLeadership(): void;
    /**
     * Stop the scheduler entirely. Clears timer and resets leader state.
     */
    stop(): void;
    /**
     * Reload the last-fired cache from the database.
     * Called after registration changes as defense-in-depth to ensure
     * the in-memory cache stays current even if registration IDs change.
     */
    refreshCache(): Promise<void>;
    /**
     * Evaluate all cron schedules and fire those that are due.
     *
     * For each schedule: uses croner to compute the most recent past scheduled
     * time. If that time is after the last-fired-at (or no last-fired exists),
     * fires the schedule.
     */
    evaluate(): Promise<void>;
    /**
     * Recover missed schedules after becoming leader.
     * Same logic as evaluate() but logs recovery context.
     */
    private recoverMissedSchedules;
    /**
     * Evaluate a single registration and fire if due.
     */
    private evaluateRegistration;
}
export {};
//# sourceMappingURL=cron-scheduler.d.ts.map