@anchan828/nest-cloud-run-queue-worker 2.0.5 → 2.0.6

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.
@@ -30,7 +30,7 @@ let QueueWorkerExplorerService = class QueueWorkerExplorerService {
30
30
  const metadata = [];
31
31
  for (const classInstanceWrapper of this.discoveryService
32
32
  .getProviders()
33
- .filter((instanceWrapper) => { var _a; return (_a = instanceWrapper.instance) === null || _a === void 0 ? void 0 : _a.constructor; })) {
33
+ .filter((instanceWrapper) => instanceWrapper.instance?.constructor)) {
34
34
  const args = Reflect.getMetadata(constants_1.QUEUE_WORKER_DECORATOR, classInstanceWrapper.instance.constructor);
35
35
  if (args && Array.isArray(args.names)) {
36
36
  for (const name of args.names) {
@@ -11,35 +11,24 @@ var __metadata = (this && this.__metadata) || function (k, v) {
11
11
  var __param = (this && this.__param) || function (paramIndex, decorator) {
12
12
  return function (target, key) { decorator(target, key, paramIndex); }
13
13
  };
14
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
15
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16
- return new (P || (P = Promise))(function (resolve, reject) {
17
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
18
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
19
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
20
- step((generator = generator.apply(thisArg, _arguments || [])).next());
21
- });
22
- };
23
14
  Object.defineProperty(exports, "__esModule", { value: true });
24
15
  exports.getWorkerController = void 0;
25
16
  const common_1 = require("@nestjs/common");
26
17
  const worker_service_1 = require("./worker.service");
27
18
  function getWorkerController(metadata) {
28
- const path = metadata === null || metadata === void 0 ? void 0 : metadata.path;
29
- const method = (metadata === null || metadata === void 0 ? void 0 : metadata.method) || common_1.RequestMethod.POST;
19
+ const path = metadata?.path;
20
+ const method = metadata?.method || common_1.RequestMethod.POST;
30
21
  let WorkerController = class WorkerController {
31
22
  constructor(service) {
32
23
  this.service = service;
33
24
  }
34
- execute(body, headers) {
35
- return __awaiter(this, void 0, void 0, function* () {
36
- yield this.service.execute(Object.assign(Object.assign({}, body.message), { headers }));
37
- });
25
+ async execute(body, headers) {
26
+ await this.service.execute({ ...body.message, headers });
38
27
  }
39
28
  };
40
29
  __decorate([
41
30
  (0, common_1.RequestMapping)({ method, path }),
42
- (0, common_1.HttpCode)((metadata === null || metadata === void 0 ? void 0 : metadata.statusCode) || 200),
31
+ (0, common_1.HttpCode)(metadata?.statusCode || 200),
43
32
  __param(0, (0, common_1.Body)()),
44
33
  __param(1, (0, common_1.Headers)()),
45
34
  __metadata("design:type", Function),
@@ -11,15 +11,6 @@ var __metadata = (this && this.__metadata) || function (k, v) {
11
11
  var __param = (this && this.__param) || function (paramIndex, decorator) {
12
12
  return function (target, key) { decorator(target, key, paramIndex); }
13
13
  };
14
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
15
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16
- return new (P || (P = Promise))(function (resolve, reject) {
17
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
18
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
19
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
20
- step((generator = generator.apply(thisArg, _arguments || [])).next());
21
- });
22
- };
23
14
  var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
24
15
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
25
16
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
@@ -48,10 +39,8 @@ let QueueWorkerService = class QueueWorkerService {
48
39
  _QueueWorkerService__allWorkers.set(this, void 0);
49
40
  }
50
41
  // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
51
- execute(rawMessage) {
52
- return __awaiter(this, void 0, void 0, function* () {
53
- yield this.runWorkers(this.isDecodedMessage(rawMessage) ? rawMessage : this.decodeMessage(rawMessage));
54
- });
42
+ async execute(rawMessage) {
43
+ await this.runWorkers(this.isDecodedMessage(rawMessage) ? rawMessage : this.decodeMessage(rawMessage));
55
44
  }
56
45
  decodeMessage(message) {
57
46
  let data;
@@ -72,32 +61,29 @@ let QueueWorkerService = class QueueWorkerService {
72
61
  raw: message,
73
62
  };
74
63
  }
75
- runWorkers(decodedMessage) {
76
- var _a, _b, _c, _d, _e, _f;
77
- return __awaiter(this, void 0, void 0, function* () {
78
- const maxRetryAttempts = (_a = this.options.maxRetryAttempts) !== null && _a !== void 0 ? _a : 1;
79
- const workers = [];
80
- workers.push(...__classPrivateFieldGet(this, _QueueWorkerService_instances, "a", _QueueWorkerService_allWorkers_get).filter((worker) => decodedMessage.data.name === worker.name));
81
- if (((_b = this.options) === null || _b === void 0 ? void 0 : _b.throwModuleError) && workers.length === 0 && __classPrivateFieldGet(this, _QueueWorkerService_instances, "a", _QueueWorkerService_spetialWorkers_get).length === 0) {
82
- throw new common_1.BadRequestException((0, constants_1.ERROR_WORKER_NOT_FOUND)(decodedMessage.data.name));
64
+ async runWorkers(decodedMessage) {
65
+ const maxRetryAttempts = this.options.maxRetryAttempts ?? 1;
66
+ const workers = [];
67
+ workers.push(...__classPrivateFieldGet(this, _QueueWorkerService_instances, "a", _QueueWorkerService_allWorkers_get).filter((worker) => decodedMessage.data.name === worker.name));
68
+ if (this.options?.throwModuleError && workers.length === 0 && __classPrivateFieldGet(this, _QueueWorkerService_instances, "a", _QueueWorkerService_spetialWorkers_get).length === 0) {
69
+ throw new common_1.BadRequestException((0, constants_1.ERROR_WORKER_NOT_FOUND)(decodedMessage.data.name));
70
+ }
71
+ const processors = (0, util_1.sortByPriority)(workers)
72
+ .map((w) => (0, util_1.sortByPriority)(w.processors))
73
+ .flat();
74
+ const spetialProcessors = (0, util_1.sortByPriority)(__classPrivateFieldGet(this, _QueueWorkerService_instances, "a", _QueueWorkerService_spetialWorkers_get))
75
+ .map((w) => (0, util_1.sortByPriority)(w.processors))
76
+ .flat();
77
+ const processorStatus = await this.options.extraConfig?.preProcessor?.(decodedMessage.data.name, decodedMessage.data.data, decodedMessage.raw);
78
+ if (processorStatus !== interfaces_1.QueueWorkerProcessorStatus.SKIP) {
79
+ for (const processor of processors) {
80
+ await this.execProcessor(processor.processor, maxRetryAttempts, decodedMessage.data.data, decodedMessage.raw);
83
81
  }
84
- const processors = (0, util_1.sortByPriority)(workers)
85
- .map((w) => (0, util_1.sortByPriority)(w.processors))
86
- .flat();
87
- const spetialProcessors = (0, util_1.sortByPriority)(__classPrivateFieldGet(this, _QueueWorkerService_instances, "a", _QueueWorkerService_spetialWorkers_get))
88
- .map((w) => (0, util_1.sortByPriority)(w.processors))
89
- .flat();
90
- const processorStatus = yield ((_d = (_c = this.options.extraConfig) === null || _c === void 0 ? void 0 : _c.preProcessor) === null || _d === void 0 ? void 0 : _d.call(_c, decodedMessage.data.name, decodedMessage.data.data, decodedMessage.raw));
91
- if (processorStatus !== interfaces_1.QueueWorkerProcessorStatus.SKIP) {
92
- for (const processor of processors) {
93
- yield this.execProcessor(processor.processor, maxRetryAttempts, decodedMessage.data.data, decodedMessage.raw);
94
- }
95
- for (const processor of spetialProcessors) {
96
- yield this.execProcessor(processor.processor, maxRetryAttempts, decodedMessage.data, decodedMessage.raw);
97
- }
82
+ for (const processor of spetialProcessors) {
83
+ await this.execProcessor(processor.processor, maxRetryAttempts, decodedMessage.data, decodedMessage.raw);
98
84
  }
99
- yield ((_f = (_e = this.options.extraConfig) === null || _e === void 0 ? void 0 : _e.postProcessor) === null || _f === void 0 ? void 0 : _f.call(_e, decodedMessage.data.name, decodedMessage.data.data, decodedMessage.raw));
100
- });
85
+ }
86
+ await this.options.extraConfig?.postProcessor?.(decodedMessage.data.name, decodedMessage.data.data, decodedMessage.raw);
101
87
  }
102
88
  isDecodedMessage(message) {
103
89
  return !!message.raw;
@@ -121,22 +107,20 @@ let QueueWorkerService = class QueueWorkerService {
121
107
  }
122
108
  return data;
123
109
  }
124
- catch (_a) {
110
+ catch {
125
111
  throw new common_1.BadRequestException(constants_1.ERROR_INVALID_MESSAGE_FORMAT);
126
112
  }
127
113
  }
128
- execProcessor(processor, maxRetryAttempts, data, raw) {
129
- return __awaiter(this, void 0, void 0, function* () {
130
- for (let i = 0; i < maxRetryAttempts; i++) {
131
- try {
132
- yield processor(data, raw);
133
- i = maxRetryAttempts;
134
- }
135
- catch (error) {
136
- this.logger.error(error.message);
137
- }
114
+ async execProcessor(processor, maxRetryAttempts, data, raw) {
115
+ for (let i = 0; i < maxRetryAttempts; i++) {
116
+ try {
117
+ await processor(data, raw);
118
+ i = maxRetryAttempts;
138
119
  }
139
- });
120
+ catch (error) {
121
+ this.logger.error(error.message);
122
+ }
123
+ }
140
124
  }
141
125
  };
142
126
  _QueueWorkerService__allWorkers = new WeakMap(), _QueueWorkerService_instances = new WeakSet(), _QueueWorkerService_allWorkers_get = function _QueueWorkerService_allWorkers_get() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anchan828/nest-cloud-run-queue-worker",
3
- "version": "2.0.5",
3
+ "version": "2.0.6",
4
4
  "description": "> TODO: description",
5
5
  "homepage": "https://github.com/anchan828/nest-cloud-run-queue/tree/master/packages/worker#readme",
6
6
  "bugs": {
@@ -33,10 +33,10 @@
33
33
  "watch": "tsc -w"
34
34
  },
35
35
  "dependencies": {
36
- "@anchan828/nest-cloud-run-queue-common": "^2.0.5"
36
+ "@anchan828/nest-cloud-run-queue-common": "^2.0.6"
37
37
  },
38
38
  "devDependencies": {
39
- "@nestjs/common": "9.0.7",
39
+ "@nestjs/common": "9.0.9",
40
40
  "rxjs": "7.5.6"
41
41
  },
42
42
  "peerDependencies": {
@@ -45,5 +45,5 @@
45
45
  "publishConfig": {
46
46
  "access": "public"
47
47
  },
48
- "gitHead": "360768b345cae02424e81dd8a581380cb0e5753d"
48
+ "gitHead": "dd78c2585bf3dcbf0dfda20310e98323b6de80f6"
49
49
  }