1

I want to make some queries in the task processor:

@Processor('audio')
export class AudioProcessor {

  constructor(private readonly entityManager: EntityManager) {

  }

  @Process()
  public async process(job: Job<any>) {
    // ! this promise never resolve
    const user = await this.entityManager.findOne(User, { id: 1 });
  }
}

The promise will never be resolved in the @Process() function.

Thanks.

鸿则_
  • 314
  • 1
  • 14

1 Answers1

0

In fact, there is an error thrown here

@Process()
public async process(job: Job<any>) {
  // error thrown below
  const user = await this.entityManager.findOne(User, { id: 1 });
}

The correct solution is use the @UseRequestContext() decorator and orm property in constructor.


constructor(
    private readonly orm: MikroORM) {

}

@Process()
@UseRequestContext()
public async process(job: Job<any>) {
  // error thrown below
  const user = await this.entityManager.findOne(User, { id: 1 });
}
鸿则_
  • 314
  • 1
  • 14