GithubHelp home page GithubHelp logo

Comments (11)

smonv avatar smonv commented on April 19, 2024

Can you provide example async configuration with custom queue name and @Queue decorator ?

from bull.

fwoelffel avatar fwoelffel commented on April 19, 2024

Hi @smonv
I'm sorry such a trivial task take me so long. I'll try to close this as soon as I find some time to do so. Until then, this may help you #13 (comment).

from bull.

smonv avatar smonv commented on April 19, 2024

Hi @fwoelffel , thank you for suggestion.

I'm trying to use Queue decorator to define a class and processor and I want inject many service to that class. Do I need inject all the service when define BullModule.forRootAsync ?

from bull.

fwoelffel avatar fwoelffel commented on April 19, 2024

Hi @smonv, I'm really sorry that it took me so long to notice your answer.
If you're using the @Queue decorator, you can inject the services you need into the targeted class. This is a simple Nest injection and should have nothing to do with BullModule.forRootAsync :)

If you're still having trouble with this, I'll try to help you in much shorter terms.

from bull.

smonv avatar smonv commented on April 19, 2024

from bull.

anitricks avatar anitricks commented on April 19, 2024

@fwoelffel hi there, i just started to use nest-bull but i am having problems with injecting services and using it inside the queue process function. Following the example you wrote I can't even access the logger. Neither the service or the logger are available in the queue.

Is this a scope problem? the queue is in the Users Module, and there is a User Service which I need to access inside the queue. So all of them are in the UsersModule, and the Service and Queue are in providers with BullModule being imported in the imports section of the UsersModule

@Module({
  imports: [
    BullModule.forRoot({
      name: 'user',
      options: {
        redis: {
          port: 0000
        }
      }
    }),
  ],
  providers: [
    UsersService,
    UsersQueue
  ],
  controllers: [UsersController],
  exports: [UsersService]
})

from bull.

fwoelffel avatar fwoelffel commented on April 19, 2024

@anitricks That should work πŸ€” Could you also share your UsersService

from bull.

anitricks avatar anitricks commented on April 19, 2024

@fwoelffel yeah sure. here is the service below. Thanks for the quick response

@Injectable()
export class UsersService extends Entity<User> {

    constructor(
        @InjectRepository(User) repo: Repository<User>,
        connection: Connection
    ) {
        super(repo, connection);
    }

    findUsers(params: { firstname?: string, lastname?: string, dob?: string }) {
        //
    }
}

its very weird. i've been scratching my head. I also have tried to put the UserQueue in the Application Module and injecting the Queue in Application Controller, however is was the same problem. Do I have to try forRootAsync because of the TypeORM module?

UsersQueue

@Queue({name: 'users'})
export class UsersQueue {

    private readonly logger = new Logger(this.constructor.name);
    constructor(private readonly service: UsersService) { }

    @QueueProcess({name: 'update'})
    async defaultFunction(job: Job) {
        console.log(this);
        let res = await this.service.findUsers({id: job.data});
        return done(null, res);
    }

from bull.

fwoelffel avatar fwoelffel commented on April 19, 2024

I don't see any issue with your code... πŸ€” Since we are drifting away from the original topic, would you be kind enough to create a new issue?

from bull.

anitricks avatar anitricks commented on April 19, 2024

yeah sorry about that. i will create a new issue

from bull.

kamilmysliwiec avatar kamilmysliwiec commented on April 19, 2024

We'll cover all that in the documentation nestjs/docs.nestjs.com#883

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.