Created
April 20, 2018 12:32
-
-
Save kubischj/8089bb60e954638cc3eb42f6b499b612 to your computer and use it in GitHub Desktop.
Kue - redis task queue
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
import * as kue from "kue"; | |
import config from "../config/config"; | |
export const Queue = kue.createQueue({ | |
prefix: "q", | |
redis: config.redis.host | |
}); | |
export const ProcessQueue = kue.createQueue(); | |
ProcessQueue.process("test", (job, done) => { | |
console.log("#==================================================#"); | |
console.log(job.data); | |
console.log("#==================================================#"); | |
done(null, { | |
success: "much", | |
process: "very", | |
resolution: "wow" | |
}); | |
}); | |
Queue | |
.create("test", { | |
title: "test", | |
to: "me@lol.com", | |
user: "me", | |
redis: config.redis.host | |
}) | |
.on("job enqueue", (id, type) => { | |
console.log( "Job %s got queued of type %s", id, type ); | |
}) | |
.on("complete", (result) => { | |
console.log("Job completed with data ", result); | |
}) | |
.on("failed attempt", () => { | |
console.warn("Job failed attempt"); | |
}) | |
.on("failed", () => { | |
console.error("Job failed utterly"); | |
}) | |
.on("progress", (progress, data) => { | |
console.log(`\r job #someid (this is the test) ${progress}% complete with data `, data ); | |
}) | |
.save((error) => { | |
if (error) { | |
console.error(error); | |
} else { | |
console.log("job saved"); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment