/** * Project Mind MCP - Job Queue Engine * * Background job execution with progress tracking and crash recovery. * Solves the 8-minute Claude timeout problem by: * - Running long operations in background * - Streaming progress every 30s (keeps Claude alive) * - Checkpointing for resume after crash * - Persisting all state to SQLite */ import { EventEmitter } from 'events'; import type { ProjectDatabase } from '../storage/database.js'; import type { JobStatus } from '../types/index.js'; export interface JobOperation { name: string; description: string; execute: (params: Record, context: JobContext) => Promise; estimateDuration?: (params: Record) => number; } export interface JobContext { jobId: number; projectId: string; updateProgress: (progress: number, step: string) => void; checkpoint: (data: Record) => void; getCheckpoint: () => Record | null; isCancelled: () => boolean; } export interface JobProgress { jobId: number; status: JobStatus; progress: number; currentStep: string; result?: unknown; error?: string; heartbeat: string; startedAt: string; completedAt?: string; } export declare class JobQueue extends EventEmitter { private db; private operations; private runningJobs; private heartbeatInterval; constructor(db: ProjectDatabase); /** * Register an operation that can be run as a job. */ registerOperation(operation: JobOperation): void; /** * Start a new background job. */ startJob(projectId: string, operationName: string, parameters: Record): Promise<{ jobId: number; status: JobStatus; estimatedDuration?: number; }>; /** * Get current progress of a job. */ getJobProgress(jobId: number): JobProgress | null; /** * List all jobs for a project. */ listJobs(projectId: string, status?: JobStatus): JobProgress[]; /** * Cancel a running job. */ cancelJob(jobId: number): boolean; /** * Resume incomplete jobs after restart. */ resumeIncompleteJobs(): Promise; /** * Shutdown the job queue cleanly. */ shutdown(): void; /** * Execute a job with progress tracking. */ private executeJob; /** * Heartbeat to keep job timestamps fresh. * Updates every 30 seconds for running jobs. */ private startHeartbeat; } //# sourceMappingURL=job-queue.d.ts.map