Skip to content

Instantly share code, notes, and snippets.

@kubischj
Created April 20, 2018 12:32
Show Gist options
  • Save kubischj/8089bb60e954638cc3eb42f6b499b612 to your computer and use it in GitHub Desktop.
Save kubischj/8089bb60e954638cc3eb42f6b499b612 to your computer and use it in GitHub Desktop.
Kue - redis task queue
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