@cloud-copilot/job
Version:
Async job runners with defined worker pools
63 lines • 1.85 kB
TypeScript
import { Job, JobResult, Logger } from './job.js';
/**
* Creates a queue that runs jobs concurrently up to a specified limit.
* This will wait for jobs to be added to it and run them up the
* maximum concurrency.
*
* Results are available via `getResults()`.
*/
export declare class ConcurrentJobQueue<T = void, P = Record<string, unknown>> {
private concurrency;
private logger;
private queue;
private results;
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.
*/
constructor(concurrency: number, logger: Logger);
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>;
/**
* Get all results accumulated so far
*/
getResults(): JobResult<T, P>[];
/**
* 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
* are available in `getResults()`.
*/
finishAllWork(): Promise<void>;
/**
* Get the current queue length
*/
get queueLength(): number;
/**
* Get the number of currently active jobs
*/
get activeJobCount(): number;
}
//# sourceMappingURL=ConcurrentJobQueue.d.ts.map