|
|
@ -33,16 +33,19 @@ export class JobsService implements OnModuleInit { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async add(name: string, data: any) { |
|
|
|
async add(name: string, data: any) { |
|
|
|
// resume primary instance queue if there is no worker
|
|
|
|
// if NC_WORKER_CONTAINER is false, then skip dynamic queue pause/resume
|
|
|
|
const workerCount = await this.jobsRedisService.workerCount(); |
|
|
|
if (process.env.NC_WORKER_CONTAINER !== 'false') { |
|
|
|
const localWorkerPaused = await this.jobsQueue.isPaused(true); |
|
|
|
// resume primary instance queue if there is no worker
|
|
|
|
|
|
|
|
const workerCount = await this.jobsRedisService.workerCount(); |
|
|
|
|
|
|
|
const localWorkerPaused = await this.jobsQueue.isPaused(true); |
|
|
|
|
|
|
|
|
|
|
|
// if there is no worker and primary instance queue is paused, resume it
|
|
|
|
// if there is no worker and primary instance queue is paused, resume it
|
|
|
|
// if there is any worker and primary instance queue is not paused, pause it
|
|
|
|
// if there is any worker and primary instance queue is not paused, pause it
|
|
|
|
if (workerCount === 0 && localWorkerPaused) { |
|
|
|
if (workerCount === 0 && localWorkerPaused) { |
|
|
|
await this.jobsQueue.resume(true); |
|
|
|
await this.jobsQueue.resume(true); |
|
|
|
} else if (workerCount > 0 && !localWorkerPaused) { |
|
|
|
} else if (workerCount > 0 && !localWorkerPaused) { |
|
|
|
await this.jobsQueue.pause(true); |
|
|
|
await this.jobsQueue.pause(true); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const job = await this.jobsQueue.add(name, data); |
|
|
|
const job = await this.jobsQueue.add(name, data); |
|
|
|