Last active
February 17, 2024 03:18
-
-
Save uratmangun/57e908ad50a910a561addd95dd287340 to your computer and use it in GitHub Desktop.
fix.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"; | |
let ready=false; | |
// @ts-ignore | |
let myQueue; | |
// @ts-ignore | |
const addJobToQueue = (data) => { | |
// @ts-ignore | |
if(ready){ | |
// @ts-ignore | |
return myQueue.add(data.jobName, data, DEFAULT_REMOVE_CONFIG); | |
}else{ | |
const connection = new Redis(CONNECTOR as any); | |
myQueue = new Queue("JOBS", { connection }); | |
myQueue.on("error", () => { | |
connection.disconnect(); | |
}); | |
connection.on("connect", function () { | |
// @ts-ignore | |
myQueue.setMaxListeners(Number(myQueue.getMaxListeners()) + 100); | |
setUpWorker(); | |
console.log("Redis client connected"); | |
}); | |
connection.on("error", function () { | |
// console.log('Something went wrong ' + err); | |
connection.disconnect(); | |
}); | |
ready=true; | |
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