Skip to content

Commit

Permalink
refactor(worker): improve instance/metatype checks
Browse files Browse the repository at this point in the history
  • Loading branch information
anchan828 committed Jan 28, 2025
1 parent 7e26ed6 commit 0a9516b
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions packages/worker/src/explorer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,25 @@ export class QueueWorkerExplorerService {

private getWorkers(): QueueWorkerMetadata[] {
const metadata: QueueWorkerMetadata[] = [];
for (const classInstanceWrapper of this.discoveryService
.getProviders()
.filter((instanceWrapper) => instanceWrapper.instance?.constructor)) {
const args = Reflect.getMetadata(
QUEUE_WORKER_DECORATOR,
classInstanceWrapper.instance.constructor,
) as QueueWorkerDecoratorArgs;
for (const classInstanceWrapper of this.discoveryService.getProviders()) {
const instance = classInstanceWrapper.instance;
const metatype = classInstanceWrapper.metatype;

if (!instance || !metatype) {
continue;
}

const args = Reflect.getMetadata(QUEUE_WORKER_DECORATOR, instance.constructor) as QueueWorkerDecoratorArgs;

if (args && Array.isArray(args.names)) {
if (args.enabled === false) {
continue;
}

for (const name of args.names) {
metadata.push({
className: classInstanceWrapper.metatype.name,
instance: classInstanceWrapper.instance,
className: metatype.name,
instance: instance,
name,
priority: args.priority || 0,
processors: [],
Expand Down

0 comments on commit 0a9516b

Please sign in to comment.