8000 Pass worker context to processors so they can pause/resume workers. · JavaScriptExpert/kue@c20c958 · GitHub
[go: up one dir, main page]

Skip to content

Commit c20c958

Browse files
committed
Pass worker context to processors so they can pause/resume workers.
1 parent 063939c commit c20c958

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

lib/queue/worker.js

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -159,32 +159,33 @@ Worker.prototype.process = function (job, fn) {
159159
// process.nextTick( function(){
160160
fn(
161161
job,
162-
/**
163-
* @author behrad
164-
* @pause: let the processor to tell worker not to continue processing new jobs
165-
*/
166-
function (err, pause) {
162+
function (err) {
167163
if (err) {
168164
return self.failed(job, err, fn);
169165
}
170166
job.complete();
171167
job.set('duration', job.duration = new Date - start);
172168
self.emit('job complete', job);
173169
events.emit(job.id, 'complete');
174-
if (pause) {
175-
self.queue.shutdown(function () {
176-
}, pause===true?5000:Number(pause), self.type);
177-
}
178170
self.job = null;
179171
self.start(fn);
180-
},
181-
/**
182-
* @author behrad
183-
* @pause: let the processor to trigger restart for they job processing
184-
*/
185-
function () {
186-
if (self.resume()) {
187-
self.start(fn);
172+
},{
173+
/**
174+
* @author behrad
175+
* @pause: let the processor to tell worker not to continue processing new jobs
176+
*/
177+
pause: function( fn, timeout ){
178+
timeout = timeout || 5000;
179+
self.queue.shutdown( fn, Number(timeout), self.type);
180+
},
181+
/**
182+
* @author behrad
183+
* @pause: let the processor to trigger restart for they job processing
184+
*/
185+
resume: function () {
186+
if (self.resume()) {
187+
self.start(fn);
188+
}
188189
}
189190
}
190191
);

0 commit comments

Comments
 (0)
0