Last active
February 17, 2024 03:18
-
-
Save uratmangun/f4ff6f4a92c0451dd934372972e675a2 to your computer and use it in GitHub Desktop.
queue.ts
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
// addJobToQueue.ts | |
import { Queue } from "bullmq"; | |
import { CONNECTOR, DEFAULT_REMOVE_CONFIG } from "./config"; | |
import setUpWorker from "./worker"; | |
import Redis from "ioredis"; | |
const connection = new Redis(CONNECTOR as any); | |
const myQueue = new Queue("JOBS", { connection }); | |
myQueue.on("error", () => { | |
connection.disconnect(); | |
}); | |
connection.on("connect", function () { | |
myQueue.setMaxListeners(Number(myQueue.getMaxListeners()) + 100); | |
setUpWorker(); | |
console.log("Redis client connected"); | |
}); | |
connection.on("error", function () { | |
// console.log('Something went wrong ' + err); | |
connection.disconnect(); | |
}); | |
// @ts-ignore | |
const addJobToQueue = (data) => { | |
// return {data,DEFAULT_REMOVE_CONFIG} | |
return myQueue.add(data.jobName, data, DEFAULT_REMOVE_CONFIG); | |
}; | |
export default addJobToQueue; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment