worker.module.ts 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. import { Module, OnApplicationShutdown, OnModuleDestroy } from '@nestjs/common';
  2. import { APP_INTERCEPTOR } from '@nestjs/core';
  3. import { ConfigModule } from '../config/config.module';
  4. import { Logger } from '../config/logger/vendure-logger';
  5. import { PluginModule } from '../plugin/plugin.module';
  6. import { ServiceModule } from '../service/service.module';
  7. import { MessageInterceptor } from './message-interceptor';
  8. import { WorkerMonitor } from './worker-monitor';
  9. import { WorkerServiceModule } from './worker-service.module';
  10. @Module({
  11. imports: [ConfigModule, ServiceModule.forWorker(), PluginModule.forWorker(), WorkerServiceModule],
  12. providers: [
  13. WorkerMonitor,
  14. {
  15. provide: APP_INTERCEPTOR,
  16. useClass: MessageInterceptor,
  17. },
  18. ],
  19. })
  20. export class WorkerModule implements OnModuleDestroy, OnApplicationShutdown {
  21. constructor(private monitor: WorkerMonitor) {}
  22. onModuleDestroy() {
  23. return this.monitor.waitForOpenTasksToComplete();
  24. }
  25. onApplicationShutdown(signal?: string) {
  26. if (signal) {
  27. Logger.info('Worker Received shutdown signal:' + signal);
  28. }
  29. }
  30. }