/** * Background Job Manager * * Manages long-running operations with persistent state. * Jobs survive session restarts - can check progress later. * * CRITICAL FIX (2025-12-09): Uses file locking to prevent race conditions * when multiple workers (clone, import, living-docs) write simultaneously. */ import type { BackgroundJob, JobConfig, JobStatus, JobType } from './types.js'; export declare class BackgroundJobManager { private projectPath; private statePath; private lockPath; constructor(projectPath: string); /** * Acquire file lock using atomic exclusive file creation * CRITICAL: Prevents race conditions between multiple worker processes */ private acquireLock; private tryCreateLockFile; private handleExistingLock; private forceAcquireLock; /** * Release file lock */ private releaseLock; /** * Create a new background job */ createJob(type: JobType, config: JobConfig, totalItems: number): BackgroundJob; /** * Start a job (mark as running) */ startJob(jobId: string): BackgroundJob | null; /** * Update job progress * * @param jobId Job ID * @param current Current item count * @param currentItem Current item being processed (for display) * @param completed Item ID that completed (appended to list) * @param failed Item ID that failed (appended to list) * @param newTotal Optional: update total count (ATOMIC - prevents race condition) */ updateProgress(jobId: string, current: number, currentItem?: string, completed?: string, failed?: string, newTotal?: number): BackgroundJob | null; /** * Complete a job */ completeJob(jobId: string, error?: string): BackgroundJob | null; /** * Complete a job with warnings (partial success). * CRITICAL (v0.33.5): Use this when most items succeeded but some failed. * Dependent jobs will treat this as success and proceed. * * Example: 252/253 repos cloned = completed_with_warnings, not failed */ completeJobWithWarnings(jobId: string, warning: string): BackgroundJob | null; /** * Pause a job (can resume later) */ pauseJob(jobId: string): BackgroundJob | null; /** * Get a specific job */ getJob(jobId: string): BackgroundJob | null; /** * Get all jobs (optionally filtered by type or status) */ getJobs(filter?: { type?: JobType; status?: JobStatus; }): BackgroundJob[]; private static readonly ACTIVE_STATUSES; /** * Get active (running/paused) jobs */ getActiveJobs(): BackgroundJob[]; private static readonly COMPLETED_STATUSES; /** * Clean up old completed jobs (keep last 10) * Uses file locking for safe concurrent access */ cleanup(): void; /** * Load state from disk */ private loadState; /** * Save state to disk */ private saveState; /** * Save a single job (merge into state) * CRITICAL FIX (2025-12-09): Uses file locking to prevent race conditions * between multiple worker processes writing simultaneously */ private saveJob; /** * Set dependency tracking fields on a job * CRITICAL FIX (2025-12-09): Must be called after createJob to persist dependsOn/dependencyStatus */ setDependencies(jobId: string, dependsOn: string[]): BackgroundJob | null; /** * Update dependency status (waiting → ready/partial) */ updateDependencyStatus(jobId: string, status: 'waiting' | 'ready' | 'partial'): BackgroundJob | null; } export declare function getJobManager(projectPath: string): BackgroundJobManager; //# sourceMappingURL=job-manager.d.ts.map