|
|
|
@ -46,28 +46,28 @@ export class JobsRedis {
|
|
|
|
|
PubSubRedis.redisSubscriber.on('message', onMessage); |
|
|
|
|
|
|
|
|
|
if (process.env.NC_WORKER_CONTAINER === 'true') { |
|
|
|
|
await this.subscribe(InstanceTypes.WORKER, async (message) => { |
|
|
|
|
await PubSubRedis.subscribe(InstanceTypes.WORKER, async (message) => { |
|
|
|
|
await onMessage(InstanceTypes.WORKER, message); |
|
|
|
|
}); |
|
|
|
|
} else { |
|
|
|
|
await this.subscribe(InstanceTypes.PRIMARY, async (message) => { |
|
|
|
|
await PubSubRedis.subscribe(InstanceTypes.PRIMARY, async (message) => { |
|
|
|
|
await onMessage(InstanceTypes.PRIMARY, message); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static async workerCount(): Promise<number> { |
|
|
|
|
if (!this.initialized) { |
|
|
|
|
if (!this.available) { |
|
|
|
|
if (!PubSubRedis.initialized) { |
|
|
|
|
if (!PubSubRedis.available) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
await this.init(); |
|
|
|
|
await PubSubRedis.init(); |
|
|
|
|
await this.initJobs(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return new Promise((resolve) => { |
|
|
|
|
this.redisClient.publish( |
|
|
|
|
PubSubRedis.redisClient.publish( |
|
|
|
|
InstanceTypes.WORKER, |
|
|
|
|
'count', |
|
|
|
|
(error, numberOfSubscribers) => { |
|
|
|
@ -84,11 +84,11 @@ export class JobsRedis {
|
|
|
|
|
|
|
|
|
|
static async emitWorkerCommand(command: InstanceCommands, ...args: any[]) { |
|
|
|
|
const data = `${command}${args.length ? `:${args.join(':')}` : ''}`; |
|
|
|
|
await this.publish(InstanceTypes.WORKER, data); |
|
|
|
|
await PubSubRedis.publish(InstanceTypes.WORKER, data); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static async emitPrimaryCommand(command: InstanceCommands, ...args: any[]) { |
|
|
|
|
const data = `${command}${args.length ? `:${args.join(':')}` : ''}`; |
|
|
|
|
await this.publish(InstanceTypes.PRIMARY, data); |
|
|
|
|
await PubSubRedis.publish(InstanceTypes.PRIMARY, data); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|