/** * Reliability layer for scheduled jobs. Serializes LLM pressure through a * semaphore, skips overlapping runs of the same jobKey, retries retryable * errors with backoff, and pauses ALL dispatch during a rate-limit cooldown. * * Deliberately storage-free: run history is recorded by the caller * (SchedulerService) around submit(). */ interface Job { /** Overlap key. WORKFLOW: workflowId, slot refresh: `${documentId}:${slotId}`. */ jobKey: string; execute: () => Promise; } type JobOutcome = { status: "success"; attempts: number; } | { status: "failed"; attempts: number; error: string; } | { status: "skipped_overlap"; attempts: 0; }; interface JobRunnerOptions { /** Max jobs executing at once. Default: env SCHEDULER_MAX_CONCURRENT or 2. */ maxConcurrent?: number; /** Waits between attempts; attempts = length + 1. */ retryDelaysMs?: number[]; /** Global dispatch pause after a rate limit without Retry-After. */ cooldownMs?: number; } declare class JobRunnerService { private maxConcurrent; private retryDelaysMs; private cooldownMs; private active; private waitQueue; private runningKeys; private cooldownUntil; private inFlight; constructor(options?: JobRunnerOptions); /** * A non-finite or <1 maxConcurrent would make `active < maxConcurrent` * permanently false, deadlocking every submitted job with no error. * Guard both the explicit option and the env-var fallback against that. */ private static resolveMaxConcurrent; submit(job: Job): Promise; /** Waits for in-flight jobs to settle (graceful shutdown). */ drain(timeoutMs?: number): Promise; private run; private waitForCooldown; private acquire; private release; } export { type Job, type JobOutcome, type JobRunnerOptions, JobRunnerService };