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

Please add an example for using classes (with deps) as processors. #5

Closed
moltar opened this issue Nov 10, 2018 · 2 comments
Closed
Assignees
Labels
question Further information is requested

Comments

@moltar
Copy link

moltar commented Nov 10, 2018

I am not sure if this is even possible, but it'd be nice to be able to define processors as regular NestJS service classes, with dependencies and all. Is that even possible?

Thanks.

@fwoelffel
Copy link
Contributor

Sure this is possible 🙂

You can inject Bull queues in your injectables :

import { Injectable, OnModuleInit } from '@nestjs/common';
import { DoneCallback, Job, Queue } from 'bull';
import { InjectQueue } from 'nest-bull';

@Injectable()
export class MyProcessor implements OnModuleInit {

  constructor (
    @InjectQueue('my_queue') private readonly queue: Queue
  ) {}


  onModuleInit() {
    this.queue.process((job: Job, done: DoneCallback) => {
      done(null, job.data);
    });
  }

}

Don't forget to provide your MyProcessor injectable.
I haven't tested this code so let me know if it works properly 😉

@fwoelffel fwoelffel self-assigned this Nov 12, 2018
@fwoelffel fwoelffel added the question Further information is requested label Nov 12, 2018
@moltar
Copy link
Author

moltar commented Nov 13, 2018

Perfect, that works! Didn't know about onModuleInit.

Thank you!

@moltar moltar closed this as completed Nov 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants