/**
 * DB-backed concurrency queue manager.
 *
 * Persists queued jobs to the concurrency_groups table and dequeues
 * the oldest queued job when a slot opens. Works with ConcurrencyGroupTracker
 * for slot-based coordination.
 */
import type { Kysely } from 'kysely';
import type { Database } from '../db/types.js';
/** A queued job returned from dequeue operations. */
export interface QueuedJob {
    id: string;
    groupKey: string;
    routingKey: string;
    runId: string;
    jobId: string;
}
/** Options for enqueueing a job. */
export interface EnqueueOptions {
    groupKey: string;
    routingKey: string;
    runId: string;
    jobId: string;
}
export declare class ConcurrencyQueueManager {
    private readonly db;
    constructor(db: Kysely<Database>);
    /**
     * Enqueue a job that is waiting for a concurrency slot.
     * Inserts a row with status='queued' into concurrency_groups.
     */
    enqueue(opts: EnqueueOptions): Promise<void>;
    /**
     * Record an active slot in the DB for persistence across restarts.
     */
    recordActive(opts: EnqueueOptions): Promise<void>;
    /**
     * Dequeue the oldest queued job for a concurrency group.
     * Returns null if no queued jobs exist.
     */
    dequeueNext(groupKey: string, routingKey: string): Promise<QueuedJob | null>;
    /**
     * Cancel all queued entries for a run.
     * Marks them as 'cancelled' with a completion timestamp.
     */
    cancelQueued(runId: string): Promise<void>;
    /**
     * Mark a concurrency group entry as completed.
     * Called when a job finishes (success/failed/cancelled).
     */
    markCompleted(runId: string, groupKey: string, routingKey: string): Promise<void>;
    /**
     * Handle job completion: mark completed and return next queued job if any.
     * This is the main coordination point: when a slot opens, the next
     * queued job should be dispatched.
     */
    onJobComplete(groupKey: string, routingKey: string, runId: string): Promise<QueuedJob | null>;
    /**
     * Load all active entries from DB for hydrating the in-memory tracker.
     * Called on orchestrator startup.
     */
    loadActiveEntries(): Promise<Array<{
        groupKey: string;
        routingKey: string;
        runId: string;
    }>>;
}
//# sourceMappingURL=queue-manager.d.ts.map