Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic queue #1235

Open
tatosjb opened this issue Nov 7, 2019 · 0 comments
Open

Dynamic queue #1235

tatosjb opened this issue Nov 7, 2019 · 0 comments

Comments

@tatosjb
Copy link

tatosjb commented Nov 7, 2019

Guys, its possible do something like that?

I want to have many queues, if i have a sequence of messages to send. Those messages have to be sent in the right sequence to the same number, but the sequence is not important between numbers.

This way works, but a think, it probably leaves a lot of leaks on the memory. Because of queue.process(job.data.phone.toString(), 1, processMessage) who may not be used after the conversation ends, for example

message-sender

  const arr = Array.from(new Array(5))
  let phones = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
  phones.forEach(async phone => {
    arr.forEach(async (_, key) => {
      let message = `${key}\t`
      queue.create('managequeue', { phone, message })
        .removeOnComplete(true)
        .save( function(err){
          if( err ) console.log(err);
        })
    })
  })

woker

const phones = []

queue.process('managequeue', 1, function(job, done){
  queue.create(job.data.phone.toString(), { phone: job.data.phone, message: job.data.message })
    .removeOnComplete(true)
    .save()

  if(!queues.includes(job.data.phone)) {
    queue.process(job.data.phone.toString(), 1, processMessage)
    phones.push(job.data.phone)
  }

  done()
  })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant