Created
October 3, 2022 03:45
-
-
Save ancyrweb/737d122337fad6c53c88a97a883695fd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Process, Processor } from '@nestjs/bull'; | |
import { Job } from 'bull'; | |
import { EmailService, SendEmailData } from './email.service'; | |
// We create an intermediary type EmailJob in case our EmailProcessor | |
// needs more information than the actual e-mail service. | |
// Just a level of indirection for now. | |
export type EmailJob = SendEmailData; | |
export const createEmailJob = (data: EmailJob): EmailJob => data; | |
@Processor('emails') | |
export class EmailProcessor { | |
constructor(private readonly emailService: EmailService) {} | |
@Process() | |
processEmail(job: Job<EmailJob>) { | |
return this.emailService.send(job.data); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment