diff --git a/lib/bull.explorer.ts b/lib/bull.explorer.ts index d36fbf3a..f000dba8 100644 --- a/lib/bull.explorer.ts +++ b/lib/bull.explorer.ts @@ -32,7 +32,19 @@ export class BullExplorer implements OnModuleInit { .getProviders() .filter((wrapper: InstanceWrapper) => this.metadataAccessor.isQueueComponent( - wrapper.inject || !wrapper.metatype + // NOTE: Regarding the ternary statement below, + // - The condition `!wrapper.metatype` is because when we use `useValue` + // the value of `wrapper.metatype` will be `null`. + // - The condition `wrapper.inject` is needed here because when we use + // `useFactory`, the value of `wrapper.metatype` will be the supplied + // factory function. + // For both cases, we should use `wrapper.instance.constructor` instead + // of `wrapper.metatype` to resolve processor's class properly. + // But since calling `wrapper.instance` could degrade overall performance + // we must defer it as much we can. But there's no other way to grab the + // right class that could be annotated with `@Processor()` decorator + // without using this property. + !wrapper.metatype || wrapper.inject ? wrapper.instance?.constructor : wrapper.metatype, ), @@ -45,6 +57,8 @@ export class BullExplorer implements OnModuleInit { name: queueName, } = this.metadataAccessor.getQueueComponentMetadata( + // NOTE: We are relying on `instance.constructor` to properly support + // `useValue` and `useFactory` providers besides `useClass`. instance.constructor || metatype, );