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

Support processor with observables #1788

Closed
1 task done
vahidvdn opened this issue Aug 18, 2023 · 1 comment
Closed
1 task done

Support processor with observables #1788

vahidvdn opened this issue Aug 18, 2023 · 1 comment
Labels

Comments

@vahidvdn
Copy link

Is there an existing issue that is already proposing this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe it

I have an observable in my processor, as following:

@Processor(BULLMQ_QUEUE_NAME)
export class JobProcessor extends WorkerHost {
  async process(job: Job<Record<string, any>>): Promise<any> {
    this.client
      .send('testFailure', 5)
      .pipe(timeout(5000))
      .subscribe({
        next: (data) => console.log('successful job', data),
        error: (err) => console.log('failed job'), // can not fail the job
      });
  }
}

With promises, I can easily await a function, and based on my condition I can throw an error as the following and mark the job as failed:

throw new Error('job failed');

But with observables, I can't do this. If I put the throw inside the error section of observable, it doesn't work, because actually before that, the job is considered completed.

Note: I prefer not to use toPromise since it's deprecated.

Describe the solution you'd like

Any possible way to accomplish this issue

Teachability, documentation, adoption, migration strategy

No response

What is the motivation / use case for changing the behavior?

Ability to use microservice client and in case of an issue with connection while sending the message, we could mark the job as failed.

@kamilmysliwiec
Copy link
Member

Please, use our Discord channel (support) for such questions. We are using GitHub to track bugs, feature requests, and potential improvements.

@nestjs nestjs locked and limited conversation to collaborators Aug 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants