@mondart/nestjs-common-module 1.1.65 → 1.1.66

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,7 +7,7 @@ const convert_string_case_helper_1 = require("./convert-string-case.helper");
7
7
  function RxjsCustomTimeoutHelper(timeoutSeconds, serviceName, methodName, config) {
8
8
  return (0, rxjs_1.timeout)({
9
9
  each: timeoutSeconds * 1000,
10
- with: () => (0, rxjs_1.throwError)(() => new common_1.GatewayTimeoutException(`${convert_string_case_helper_1.ConvertStringCaseHelper.toKebabCase(serviceName)}-` +
10
+ with: () => (0, rxjs_1.throwError)(() => new common_1.GatewayTimeoutException(`Request to ${convert_string_case_helper_1.ConvertStringCaseHelper.toKebabCase(serviceName)}/` +
11
11
  `${convert_string_case_helper_1.ConvertStringCaseHelper.toKebabCase(methodName)}: ` +
12
12
  `Timeout has occurred`)),
13
13
  ...config,
@@ -1,5 +1,8 @@
1
- import { DynamicModule } from '@nestjs/common';
1
+ import { DynamicModule, OnModuleDestroy } from '@nestjs/common';
2
2
  import { SagaModuleRegisterParams } from './interfaces';
3
- export declare class SagaModule {
3
+ export declare class SagaModule implements OnModuleDestroy {
4
+ private static activeSagas;
5
+ private logger;
4
6
  static register(params: SagaModuleRegisterParams): DynamicModule;
7
+ onModuleDestroy(): Promise<void>;
5
8
  }
@@ -10,10 +10,14 @@ var __metadata = (this && this.__metadata) || function (k, v) {
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.SagaModule = void 0;
13
+ const common_1 = require("@nestjs/common");
13
14
  const cqrs_1 = require("@nestjs/cqrs");
14
15
  const core_1 = require("@nestjs/core");
15
16
  const constant_1 = require("./constant");
16
17
  class SagaModule {
18
+ constructor() {
19
+ this.logger = new common_1.Logger(SagaModule.name, { timestamp: true });
20
+ }
17
21
  static register(params) {
18
22
  return {
19
23
  imports: [cqrs_1.CqrsModule, ...(params.imports || [])],
@@ -27,9 +31,14 @@ class SagaModule {
27
31
  this.moduleRef = moduleRef;
28
32
  }
29
33
  async execute(cmd) {
34
+ const sagaId = new Date().getTime().toString();
35
+ SagaModule.activeSagas.push(sagaId);
30
36
  const s = await this.moduleRef.create(saga);
31
37
  s.saga.bind(s);
32
- return s.execute(cmd);
38
+ const response = s.execute(cmd);
39
+ const sagaIndex = SagaModule.activeSagas.findIndex((saga) => saga === sagaId);
40
+ sagaIndex && delete SagaModule.activeSagas[sagaIndex];
41
+ return response;
33
42
  }
34
43
  };
35
44
  SagaCommandHandler = __decorate([
@@ -45,5 +54,20 @@ class SagaModule {
45
54
  ],
46
55
  };
47
56
  }
57
+ async onModuleDestroy() {
58
+ await new Promise((resolve) => {
59
+ const checkSagas = () => {
60
+ if (SagaModule.activeSagas.length) {
61
+ this.logger.warn('Waiting for sagas to complete...');
62
+ setTimeout(checkSagas, 5000);
63
+ }
64
+ else {
65
+ resolve('Done');
66
+ }
67
+ };
68
+ checkSagas();
69
+ });
70
+ }
48
71
  }
49
72
  exports.SagaModule = SagaModule;
73
+ SagaModule.activeSagas = [];