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.
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 });
}