GithubHelp home page GithubHelp logo

Global concurrency limit about bull HOT 5 CLOSED

mgpai22 avatar mgpai22 commented on April 27, 2024
Global concurrency limit

from bull.

Comments (5)

mgpai22 avatar mgpai22 commented on April 27, 2024 1

Thank you, this is working well for me! Will still leave this issue up because I think the ability to do this globally will be useful.

from bull.

mgpai22 avatar mgpai22 commented on April 27, 2024

Here is the concurrency documentation on the bullMQ side: https://docs.bullmq.io/guide/workers/concurrency

from bull.

mckrava avatar mckrava commented on April 27, 2024

I have similar issue but docs above provided me not "optimistic" info. So could you check correctness of my understanding:
So I have 1 queue and named jobs in this queue (create_post, update_post, follow_post, etc.). These events must be processed in the same order as they were added to the queue (it's required) and parallel processing is not allowed. So here is my @processor class:

@Processor('SOCIAL_ENTITY_JOBS')
export class Processor {
  constructor() {}

  @Process({ name: 'create_post', concurrency: 1 })
  async create_post(job: Job<unknown>) {
    // handling logic is here
  }

  @Process({ name: 'update_post', concurrency: 1 })
  async update_post(job: Job<unknown>) {
    // handling logic is here
  }
}

as result if I define only one @process for jobs create_post so concurrency: 1 works correct and jobs are processing one by one. But when I add @process for update_post jobs, concurrency doesn't work anymore and I have 2 parallel processing of even the same job create_post. This behaviour is in nest/bull documentation

WARNING
When defining multiple consumers for the same queue, the concurrency option in @Process({ concurrency: 1 }) won't take effect. The minimum concurrency will match the number of consumers defined. This also applies even if @Process() handlers use a different name to handle named jobs.

But, what if I need exactly global concurrency for this queue?

from bull.

mckrava avatar mckrava commented on April 27, 2024

This thread was like a yellow duck for me so after my post I realised a solution. If it's still interesting for smb (@mgpai22 ):
Check this section in Bull docs and especially this part Specifying * as the process name will make it the default processor for all named jobs..
As result my solution looks like this:

@Processor('SOCIAL_ENTITY_JOBS')
export class Processor {
  constructor() {}
  
  @Process({ name: '*', concurrency: 1 })
  async processJob(job: Job<unknown>) {
    switch (job.name) {
      case "create_post":
        return this.create_post(job);
      case "update_post":
        return this.update_post(job);
    }
  }

  async create_post(job: Job<unknown>) {
    // handling logic is here
  }

  async update_post(job: Job<unknown>) {
    // handling logic is here
  }
}

from bull.

kamilmysliwiec avatar kamilmysliwiec commented on April 27, 2024

@nestjs/bull is just a simple wrapper of bull package so if you need any extra features you should report this fr/issue in their repository.

from bull.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.