Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
i++;
}
i = 0;
while(i < 500){
queue.enqueue('slowQueue', "slowSleepJob", []);
i++;
}
});
//////////
// WORK //
//////////
var multiWorker = new NR.multiWorker({
connection: connectionDetails,
queues: ['slowQueue'],
minTaskProcessors: 1,
maxTaskProcessors: 20,
}, jobs);
// normal worker emitters
multiWorker.on('start', function(workerId){ console.log("worker["+workerId+"] started"); });
multiWorker.on('end', function(workerId){ console.log("worker["+workerId+"] ended"); });
multiWorker.on('cleaning_worker', function(workerId, worker, pid){ console.log("cleaning old worker " + worker); });
multiWorker.on('poll', function(workerId, queue){ console.log("worker["+workerId+"] polling " + queue); });
multiWorker.on('job', function(workerId, queue, job){ console.log("worker["+workerId+"] working job " + queue + " " + JSON.stringify(job)); });
multiWorker.on('reEnqueue', function(workerId, queue, job, plugin){ console.log("worker["+workerId+"] reEnqueue job (" + plugin + ") " + queue + " " + JSON.stringify(job)); });
multiWorker.on('success', function(workerId, queue, job, result){ console.log("worker["+workerId+"] job success " + queue + " " + JSON.stringify(job) + " >> " + result); });
multiWorker.on('failure', function(workerId, queue, job, failure){ console.log("worker["+workerId+"] job failure " + queue + " " + JSON.stringify(job) + " >> " + failure); });
multiWorker.on('error', function(workerId, queue, job, error){ console.log("worker["+workerId+"] error " + queue + " " + JSON.stringify(job) + " >> " + error); });
startMultiWorker (callback) {
let self = this
self.workerLogging = self.api.config.tasks.workerLogging
self.schedulerLogging = self.api.config.tasks.schedulerLogging
// create a new multiworker instance
let MultiWorker = NR.multiWorker
self.multiWorker = new MultiWorker({
connection: self.connectionDetails,
queues: self.api.config.tasks.queues,
timeout: self.api.config.tasks.timeout,
checkTimeout: self.api.config.tasks.checkTimeout,
minTaskProcessors: self.api.config.tasks.minTaskProcessors,
maxTaskProcessors: self.api.config.tasks.maxTaskProcessors,
maxEventLoopDelay: self.api.config.tasks.maxEventLoopDelay,
toDisconnectProcessors: self.api.config.tasks.toDisconnectProcessors
}, self.api.tasks.jobs)
// normal worker emitters
self.multiWorker.on('start', workerId => self.api.log('worker: started', self.workerLogging.start, { workerId: workerId }))
self.multiWorker.on('end', workerId => self.api.log('worker: ended', self.workerLogging.end, { workerId: workerId }))
self.multiWorker.on('cleaning_worker', (workerId, worker, pid) => self.api.log(`worker: cleaning old worker ${worker}, (${pid})`, self.workerLogging.cleaning_worker))
// for debug: self.multiWorker.on('poll', (queue) => self.api.log(`worker: polling ${queue}`, self.workerLogging.poll))
log: koop.log,
cache: koop.cache
}
var cache = new Cache(cacheOpts)
var workOpts = {
connection: config.queue.connection,
cache: cache,
log: koop.log,
files: koop.fs,
queue: koop.queue
}
var work = new Work(workOpts)
var multiWorker = new MultiWorker({
connection: work.connection,
queues: ['agol'],
minTaskProcessors: 10,
maxTaskProcessors: 100,
checkTimeout: 1000,
maxEventLoopDelay: 10,
toDisconnectProcessors: true
}, work.jobs)
multiWorker.start()
multiWorker.on('start', function (workerId) {
koop.log.info('worker[' + workerId + '] started')
})
multiWorker.on('end', function (workerId) {
koop.log.info('worker[' + workerId + '] ended')