UNPKG

@cloud-copilot/job

Version:

Async job runners with defined worker pools

62 lines 2.09 kB
import { Job, JobResult, Logger } from './job.js'; /** * A queue that will run jobs concurrently using promises up to a specified limit. * If no work is being done, it will wait for jobs to be added and run them up to the * maximum concurrency. * * Results are not stored in this queue, but are processed immediately via the `onComplete` callback. * */ export declare class StreamingJobQueue<T = void, P = Record<string, unknown>> { private concurrency; private logger; private onComplete; private queue; private activeJobs; private waitingResolvers; private workers; private isAcceptingWork; private workAvailablePromise; private resolveWorkAvailable; /** * Create a new runner with the specified concurrency. * * @param concurrency - The maximum number of jobs to run concurrently. * @param logger - Logger instance for logging long-running jobs. * @param onComplete - Callback to handle job completion, receives the job result. */ constructor(concurrency: number, logger: Logger, onComplete: (response: JobResult<T, P>) => Promise<void>); private worker; private waitForWorkAvailable; private ensureWorkers; private notifyWorkersOfNewWork; private checkIfIdle; /** * Add a job to the queue */ enqueue(job: Job<T, P>): void; /** * Add multiple jobs to the queue */ enqueueAll(jobs: Job<T, P>[]): void; /** * Returns a promise that resolves when all queued work is complete */ waitForIdle(): Promise<void>; /** * Shutdown the queue - no new jobs will be accepted, but existing jobs will complete. * * Returns when a promise that resolves when all jobs have been processed and * the onComplete callback has been called for each job. */ finishAllWork(): Promise<void>; /** * Get the current queue length */ get queueLength(): number; /** * Get the number of currently active jobs */ get activeJobCount(): number; } //# sourceMappingURL=StreamingJobQueue.d.ts.map