refactor(core): Suppress MaxListenersExceededWarning in the logs (#10077)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™ 2024-07-16 18:20:55 +02:00 committed by GitHub
parent 48f047ee2e
commit 3bbeae47f3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 22 additions and 6 deletions

View file

@ -35,6 +35,24 @@ export interface WebhookResponse {
export class Queue {
private jobQueue: JobQueue;
/**
* The number of jobs a single server can process concurrently
* Any worker that wants to process executions must first set this to a non-zero value
*/
private concurrency = 0;
setConcurrency(concurrency: number) {
this.concurrency = concurrency;
// This sets the max event listeners on the jobQueue EventEmitter to prevent the logs getting flooded with MaxListenersExceededWarning
// see: https://github.com/OptimalBits/bull/blob/develop/lib/job.js#L497-L521
this.jobQueue.setMaxListeners(
4 + // `close`
2 + // `error`
2 + // `global:progress`
concurrency * 2, // 2 global events for every call to `job.finished()`
);
}
constructor(private activeExecutions: ActiveExecutions) {}
async init() {
@ -102,8 +120,8 @@ export class Queue {
return new Set(inProgressJobs.map((job) => job.data.executionId));
}
async process(concurrency: number, fn: Bull.ProcessCallbackFunction<JobData>): Promise<void> {
return await this.jobQueue.process(concurrency, fn);
async process(fn: Bull.ProcessCallbackFunction<JobData>): Promise<void> {
return await this.jobQueue.process(this.concurrency, fn);
}
async ping(): Promise<string> {

View file

@ -320,11 +320,9 @@ export class Worker extends BaseCommand {
const envConcurrency = config.getEnv('executions.concurrency.productionLimit');
const concurrency = envConcurrency !== -1 ? envConcurrency : flags.concurrency;
Worker.jobQueue.setConcurrency(concurrency);
void Worker.jobQueue.process(
concurrency,
async (job) => await this.runJob(job, this.nodeTypes),
);
void Worker.jobQueue.process(async (job) => await this.runJob(job, this.nodeTypes));
Worker.jobQueue.getBullObjectInstance().on('global:progress', (jobId: JobId, progress) => {
// Progress of a job got updated which does get used