0

in order to manage the traffic and effectively process a particular message, / we have implemented a rate limited bull queue :- but we are not able to acheive rate limiting . Here is my implementation , but rate limiting in this queue is not working

const createNewQueue = async({ queueName, queueOpts = {}, defaultJobOpts = null, queueUrl = null }) =>{
try{
    console.log("createNewQueue fn called")
    if(defaultJobOpts){
        queueOpts.defaultJobOptions = defaultJobOpts
    }
    queueOpts['redis'] ={
      port:process.env.CS_REDIS_PORT,
      host:process.env.CS_REDIS_URL,
      password:process.env.CS_REDIS_PASSWORD
    }
    queueUrl = queueUrl ? queueUrl : redisUrl
    const newQueue = new Queue(queueName , queueOpts )
    console.log("\n\n\n queue created ------\n", newQueue)
    Queues[queueName] = newQueue
    return newQueue
}
catch(err){
    handleAppError({err})
}

}

const inputQueue = {
queueName: 'inputQueue',
processLeftJobs: true,
processOptions: {
  concurrency: 1
},
cleanQueue: true,
cleanQueueEvents: [
  'completed'
],
queueOpts:{
  limiter: {
    max: 1000,
    duration: 10000
  }
}

}

await createNewQueue(inputQueue)
SuperStormer
  • 4,997
  • 5
  • 25
  • 35
Harshit_Rana
  • 59
  • 2
  • 7
  • Your function is `async`, but there is nothing asynchronous in your function; or am I missing something? Moreover, there is nothing in your code that does anything related to rate limiting: the `max` and `duration` values are nowhere used in the code you shared, so what do you expect? – trincot Apr 28 '21 at 17:00
  • @trincot , please see i have a object named inputQueue , where you can see values like max and duration under queueOpts... – Harshit_Rana Apr 28 '21 at 18:10
  • Yes, I saw that object, but your code never uses them. – trincot Apr 28 '21 at 18:10
  • @trincot , see the last line where in i have written this :- createNewQueue(inputQueue) – Harshit_Rana Apr 28 '21 at 18:15
  • OK, I don't know how `Queue` works in Bull. I suppose there is documentation you can use. But ignoring that, I don't see anything that warrants the use of `async` / `await`. – trincot Apr 28 '21 at 18:16
  • As far as I understand you are creating queues, but you never put anything in those queues. Shouldn't you be creating *one* queue, and *add* jobs to it? See the `add` method, which returns a promise and would give sense to your `async`. – trincot Apr 28 '21 at 18:23
  • yes , i have not show job adding part here ..... My point was to show the configuration , if anything is wrong in that – Harshit_Rana Apr 29 '21 at 04:58

0 Answers0