launch (name, params = {}, priority = 'normal', removeOnComplete = false) { logger.debug('Launching %s job with params', name, params) return new Promise((resolve, reject) => { const job = this.queue .create(name, params) .priority(priority) .removeOnComplete(removeOnComplete) .save(err => err ? reject(err) : resolve(job)) }) }
this.q.create(name, data) .priority(options.priority || 'normal') .removeOnComplete(options.removeOnComplete || false) .attempts(options.attempts) .ttl((options.ttl ? options.ttl + this.ttl_buffer : 10000 + this.ttl_buffer )) // 10s .backoff(options.backoff) .delay(options.delay) .save(function(err){ debug('Add job ' + job.type + '(' + job.id + ') ' + JSON.stringify(data)) fn && fn(err) })
stream.on('data', function (doc) { kue.create('randomize-document', { title: 'Randomize document', params: { type : 'randomize-document', model : model, id : doc._id.toString() } }).attempts(3).removeOnComplete(true).save(); }).on('error', function (err) { console.error(err.stack); }).on('end', function () { console.log(model+' randomize sync stream end'); });
sync(model, kue) { const self = this; // update model const m = self._mongoose.model(model); const stream = m.find({}).stream({transform}); stream.on('data', doc => { kue.create('randomize-document', { title: 'Randomize document', params: { type: 'randomize-document', id: doc._id.toString(), model, }, }).attempts(3).removeOnComplete(true).save(); }).on('error', err => { console.error(err.stack); }).on('end', () => { console.log(`${model} randomize sync stream end`); }); return stream; }
it('Remove completed job if removeOnComplete is set to true', function(done){ spinal.worker('test-d', function (data, res) { res.send(data.stock) }) spinal.start(function() { spinal.job('q-test-client.test-d', {stock: 'TSLA'}) .removeOnComplete(true) .onComplete(function (result) { expect(result).to.equal('TSLA') broker.queue.q.complete(function (err, ids) { expect(ids.length).to.equal(0) done() }) }) .save() }) })
stream.on('data', function (doc) { console.log(model+' doc denormalize job: '+doc._id.toString()); kue.create('denormalize-document', { title: 'Denormalize document', params: { type: 'denormalize-document', model: model, id: doc._id.toString() } }).attempts(3).removeOnComplete(true).save(); }).on('error', function (err) { console.error(err.stack); }).on('end', function () { console.log(model+' sync stream end'); });
/** * Save task * @param {*} args */ const saveJob = args => { const { type, data, options = {} } = args; const { delay, priority, attempts, remove } = { ...defaults, ...options }; const job = queue .create(type, data) .delay(delay) .priority(priority) .attempts(attempts) .removeOnComplete(remove) .save(err => { if (err) winston.error(`Error occurred during creating a Kue task: ${boom.boomify(err)}`); }); return job; }
new _schema('feed.channels').init(app).stream({}, function(err, stream) { stream.on('data', function (doc) { var docId = doc._id.toString(); _log.info(_group, 'denormalize job, '+docId); _kue.create('feed-channel-parse', { title: 'Feed channel parse', params: { type: 'feed-channel-parse', channel: docId } }).attempts(3).removeOnComplete(true).save(); }).on('error', function (err) { _log.error(_group, err); }).on('close', function () { _log.info(_group, 'stream finished'); }); });
id: doc._id.toString(), }, }).attempts(3).removeOnComplete(true).save(); }).on('error', err => { self.helper.log('error', err);
describe('SQSWorker', function() { it('should create task', function () { var worker = new SQSWorker(sqs, 'some-queue-url') worker .create() .removeOnComplete() .ttl(30) .attempts(10) .delay(3) .save() }); it('should process task', function () { var worker = new SQSWorker(sqs, 'some-queue-url') worker.process('hi', function() {}) }); it('should shutdown', function (cb) { var worker = new SQSWorker(sqs, 'some-queue-url') worker.shutdown(5, cb) }); it('should watchStuckJobs', function () { var worker = new SQSWorker(sqs, 'some-queue-url') worker.watchStuckJobs() }); });
const kueTask = queue.create('task-' + id, task).attempts(task.attemptsLimit || options.attemptsLimit || 1).removeOnComplete(true).save();
const kueTask = queue.create('task-' + id, task) .attempts(task.attemptsLimit || options.attemptsLimit || 1) .removeOnComplete(true) .save()