Created
June 18, 2012 17:35
-
-
Save slightair/2949580 to your computer and use it in GitHub Desktop.
sample for kue issue #110
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var kue = require('kue'); | |
var jobs = kue.createQueue(); | |
jobs.process('job', function(job, done){ | |
var progressMax = 3; | |
var next = function(i){ | |
console.log("job-%d-%s [%d/%d] #%d", job.data.id, job.data.title, i, progressMax, job.id); | |
job.progress(i, progressMax); | |
if (i == progressMax) { | |
done(); | |
} | |
else { | |
setTimeout(function(){ | |
next(i+1); | |
}, 100); | |
} | |
} | |
next(1); | |
}); | |
jobs.on('job promotion', function(id){ | |
kue.Job.get(id, function(err, job){ | |
console.log('job promotion #%d', job.id); | |
if (err) return; | |
}); | |
}); | |
for (i=0;i<3;i++) { | |
jobs.create('job', {id:i, title:"normal"}).on('complete', function(){ | |
console.log('complete #%d', this.id); | |
}).save(); | |
} | |
for (i=0;i<3;i++) { | |
jobs.create('job', {id:i, title:"delayed"}).on('promotion', function(){ | |
console.log('promotion #%d', this.id); | |
}).on('complete', function(){ | |
console.log('complete #%d', this.id); | |
}).delay(3000).save(); | |
} | |
jobs.promote(100); | |
// result | |
// job-0-normal [1/3] #223 | |
// job-0-normal [2/3] #223 | |
// job-0-normal [3/3] #223 | |
// complete #223 | |
// job-1-normal [1/3] #224 | |
// job-1-normal [2/3] #224 | |
// job-1-normal [3/3] #224 | |
// complete #224 | |
// job-2-normal [1/3] #225 | |
// job-2-normal [2/3] #225 | |
// job-2-normal [3/3] #225 | |
// complete #225 | |
// promotion #226 | |
// job promotion #226 | |
// job-1-delayed [1/3] #227 | |
// job promotion #226 | |
// job promotion #226 | |
// job-1-delayed [2/3] #227 | |
// job-1-delayed [3/3] #227 | |
// complete #227 | |
// job-0-delayed [1/3] #226 | |
// job-0-delayed [2/3] #226 | |
// job-0-delayed [3/3] #226 | |
// job-2-delayed [1/3] #228 | |
// job-2-delayed [2/3] #228 | |
// job-2-delayed [3/3] #228 | |
// complete #228 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
logged "job promotion #226" 3 times.
and missing "complete #226".