Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dunklesToast/4470718d169e24337d20cff20ff3146d to your computer and use it in GitHub Desktop.
Save dunklesToast/4470718d169e24337d20cff20ff3146d to your computer and use it in GitHub Desktop.
small example of how to use mikroorm's CreateRequestContext decorator with queues in NestJS
@Injectable()
@Processor('processor')
export class Processor {
constructor(
private readonly service: Service,
// this is needed for the CreateRequestContext decorators
private readonly orm: MikroORM,
private entityManager: EntityManager,
) {}
@CreateRequestContext()
private doSomethingOnTheDatabase(id: string) {
return this.service.findSomethingFromDatabase(id);
}
@Process()
async generate(job: Job) {
await this.doSomethingOnTheDatabase(job.data.resourceId);
return {};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment