Skip to content

Instantly share code, notes, and snippets.

@ancyrweb
Created October 3, 2022 03:45
Show Gist options
  • Save ancyrweb/737d122337fad6c53c88a97a883695fd to your computer and use it in GitHub Desktop.
Save ancyrweb/737d122337fad6c53c88a97a883695fd to your computer and use it in GitHub Desktop.
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