Created
January 21, 2018 13:31
-
-
Save dturton/7356f81718080841f14dfe14aa4052ff to your computer and use it in GitHub Desktop.
node.js kue and express
This file contains 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
import kue from 'kue' | |
import express from 'express' | |
const app = express(); | |
const jobs = kue.createQueue() | |
app.use('/api', kue.app); | |
app.get('/job', (req, res) => { | |
let job = jobs.create( 'email', { | |
title: 'emailing ' | |
}) | |
job.on('complete', function(){ | |
res.send("Job complete"); | |
}).on('failed', function(){ | |
res.send("Job failed"); | |
}).on('progress', function(progress){ | |
console.log('job #' + job.id + ' ' + progress + '% complete'); | |
}) | |
job.save((err) => { | |
if( !err ) res.json(job.id); | |
}); | |
}) | |
jobs.process('email', function(job, done){ | |
setTimeout(() => { | |
done() | |
}, 5000); | |
}); | |
app.listen(8080, function() { | |
console.log("Listening on http://localhost:8080"); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You want the consumer and the producer to be on different processes.
I haven't checked the code below, and it is 1AM, so... take with a grain of salt, @dturton ! :)