/**
 * Queue Service for background job processing
 * Based on patterns from mila-ai but enhanced with TypeScript and better error handling
 */
import { EventEmitter } from "events";
export interface QueueJob {
    id: string;
    type: string;
    data: any;
    status: "pending" | "processing" | "completed" | "failed";
    priority: number;
    retries: number;
    maxRetries: number;
    createdAt: Date;
    updatedAt: Date;
    processedAt?: Date;
    error?: string;
}
export interface QueueConfig {
    maxConcurrentJobs?: number;
    pollingInterval?: number;
    maxRetries?: number;
    enablePersistence?: boolean;
}
export type JobHandler = (job: QueueJob) => Promise<void>;
export declare class QueueService extends EventEmitter {
    private jobs;
    private handlers;
    private isRunning;
    private activeJobs;
    private config;
    private pollingTimer?;
    private fileHandler;
    constructor(config?: QueueConfig);
    /**
     * Register a job handler
     */
    registerHandler(jobType: string, handler: JobHandler): void;
    /**
     * Add a job to the queue
     */
    addJob(type: string, data: any, priority?: number): Promise<string>;
    /**
     * Start processing jobs
     */
    start(): Promise<void>;
    /**
     * Stop processing jobs
     */
    stop(): Promise<void>;
    /**
     * Process the next job in the queue
     */
    private processNextJob;
    /**
     * Get the next pending job based on priority
     */
    private getNextPendingJob;
    /**
     * Mark a job as completed
     */
    private completeJob;
    /**
     * Handle job error
     */
    private handleJobError;
    /**
     * Mark a job as failed
     */
    private failJob;
    /**
     * Move failed job to dead-letter queue
     */
    private moveToDeadLetterQueue;
    /**
     * Start polling for jobs
     */
    private startPolling;
    /**
     * Persist job to file
     */
    private persistJob;
    /**
     * Load persisted jobs
     */
    private loadPersistedJobs;
    /**
     * Get queue statistics
     */
    getStats(): {
        total: number;
        pending: number;
        processing: number;
        completed: number;
        failed: number;
        activeJobs: number;
    };
    /**
     * Get job by ID
     */
    getJob(jobId: string): QueueJob | undefined;
    /**
     * Get all jobs
     */
    getAllJobs(): QueueJob[];
    /**
     * Clear completed and failed jobs
     */
    clearFinishedJobs(): void;
}
export default QueueService;
//# sourceMappingURL=queueService.d.ts.map