Proper use of Ts.ED BullMQ on server init

50 views Asked by At

I'm using Tsed(newb) and want to use the BullMQ plugin.

I want to run a job right after the server starts but I'm not sure how to do it properly. I've been following this guide https://tsed.io/tutorials/bullmq.html and I've tried this beforehand.

import { JobDispatchService } from "./services/jobDispatchService"; // from https://tsed.io/tutorials/bullmq.html#dispatching-jobs

export class Server {
  @Inject()
  app: PlatformApplication;

  @Inject()
  dispatcher: JobDispatchService;

  @Configuration()
  settings: Configuration;

  $beforeRoutesInit(): void {
    this.app
      .use(URLMiddleware)
      .use(cors())
      .use(cookieParser())
      .use(compress({}))
      .use(methodOverride())
      .use(bodyParser.json())
      .use(
        bodyParser.urlencoded({
          extended: true
        })
      );
  }

  $afterRoutesInit(): void {
    $log.error("after init");
    console.log("should check notif");
    this.dispatcher.doingSomething()
  }
}

I get this error when starting the server.

[2023-12-15T01:09:33.035] [DEBUG] [TSED] - Start server...
[2023-12-15T01:09:33.043] [INFO ] [TSED] - Injector created... +6ms
[2023-12-15T01:09:35.022] [INFO ] [TSED] - Providers loaded... +1979ms
[2023-12-15T01:09:35.022] [INFO ] [TSED] - Build providers +0ms
query: SELECT * FROM current_schema()
query: SHOW server_version;
[2023-12-15T01:09:35.106] [INFO ] [TSED] - Connected with typeorm to database: default
[2023-12-15T01:09:35.142] [ERROR] [TSED] - TypeError: this.injector.getMany is not a function
    at BullMQModule.$beforeInit (/home//dashboard/packages/aservice/node_modules/@tsed/bullmq/src/BullMQModule.ts:28:19)
    at LocalsContainer.emit (/home//dashboard/packages/aservice/node_modules/@tsed/di/src/domain/LocalsContainer.ts:12:13)
    at InjectorService.load (/home//dashboard/packages/aservice/node_modules/@tsed/di/src/services/InjectorService.ts:313:18)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at PlatformBuilder.loadInjector (/home//dashboard/packages/aservice/node_modules/@tsed/common/src/builder/PlatformBuilder.ts:202:5)
    at PlatformBuilder.runLifecycle (/home//dashboard/packages/aservice/node_modules/@tsed/common/src/builder/PlatformBuilder.ts:180:5)
    at bootstrap (/home//dashboard/packages/aservice/src/index.ts:8:22)
1

There are 1 answers

0
Romain Lenzotti On

Your issue seems to be related to a wrong dependencies installed on your project. One of the rule of Ts.ED framework is to have the same version for all @tsed/* packages (excepted for the @tsed/logger).

WARNING

If you have to upgrade Ts.ED dependencies, keep in mind this point:

It's really important to keep the same version for all @tsed/* (excepted @tsed/logger) packages. To prevent errors, fix the version for each Ts.ED packages:

{
  "dependencies": {
    "@tsed/common": "7.53.0",
    "@tsed/di": "7.53.0",
    "@tsed/core": "7.53.0",
    "@tsed/exceptions": "7.53.0",
    "@tsed/plaftorm-express": "7.53.0",
    "@tsed/swagger": "7.53.0"
  }
}

To have a quick answer to your issue, it's recommended to open issue directly on github.

See you