@anchan828/nest-cloud-run-queue-worker 2.2.0 → 2.2.1

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.
@@ -1,4 +1,5 @@
1
1
  import { QueueWorkerName } from "@anchan828/nest-cloud-run-queue-common";
2
+ import { QueueWorkerOptions, QueueWorkerProcessOptions } from "./interfaces";
2
3
  /**
3
4
  * Define worker
4
5
  *
@@ -9,6 +10,7 @@ import { QueueWorkerName } from "@anchan828/nest-cloud-run-queue-common";
9
10
  */
10
11
  export declare function QueueWorker(name: QueueWorkerName, priority?: number): ClassDecorator;
11
12
  export declare function QueueWorker(names: QueueWorkerName[], priority?: number): ClassDecorator;
13
+ export declare function QueueWorker(options: QueueWorkerOptions): ClassDecorator;
12
14
  /**
13
15
  * Define worker processor
14
16
  *
@@ -17,3 +19,4 @@ export declare function QueueWorker(names: QueueWorkerName[], priority?: number)
17
19
  * @returns {MethodDecorator}
18
20
  */
19
21
  export declare function QueueWorkerProcess(priority?: number): MethodDecorator;
22
+ export declare function QueueWorkerProcess(options?: QueueWorkerProcessOptions): MethodDecorator;
@@ -4,19 +4,28 @@ exports.QueueWorker = QueueWorker;
4
4
  exports.QueueWorkerProcess = QueueWorkerProcess;
5
5
  const common_1 = require("@nestjs/common");
6
6
  const constants_1 = require("./constants");
7
- function QueueWorker(names, priority = 0) {
7
+ function QueueWorker(nameOrOptions, priority = 0) {
8
+ if (Array.isArray(nameOrOptions)) {
9
+ return (0, common_1.SetMetadata)(constants_1.QUEUE_WORKER_DECORATOR, {
10
+ names: nameOrOptions,
11
+ priority,
12
+ });
13
+ }
14
+ if (typeof nameOrOptions === "string") {
15
+ return (0, common_1.SetMetadata)(constants_1.QUEUE_WORKER_DECORATOR, {
16
+ names: [nameOrOptions],
17
+ priority,
18
+ });
19
+ }
8
20
  return (0, common_1.SetMetadata)(constants_1.QUEUE_WORKER_DECORATOR, {
9
- names: Array.isArray(names) ? names : [names],
10
- priority,
21
+ enabled: nameOrOptions.enabled,
22
+ names: Array.isArray(nameOrOptions.name) ? nameOrOptions.name : [nameOrOptions.name],
23
+ priority: nameOrOptions.priority || 0,
11
24
  });
12
25
  }
13
- /**
14
- * Define worker processor
15
- *
16
- * @export
17
- * @param {number} [priority=0] Highest priority is 0, and lower the larger integer you use.
18
- * @returns {MethodDecorator}
19
- */
20
- function QueueWorkerProcess(priority = 0) {
21
- return (0, common_1.SetMetadata)(constants_1.QUEUE_WORKER_PROCESS_DECORATOR, { priority });
26
+ function QueueWorkerProcess(priorityOrOptions) {
27
+ const options = typeof priorityOrOptions === "number"
28
+ ? { priority: priorityOrOptions }
29
+ : Object.assign({ priority: 0 }, priorityOrOptions);
30
+ return (0, common_1.SetMetadata)(constants_1.QUEUE_WORKER_PROCESS_DECORATOR, options);
22
31
  }
@@ -33,6 +33,9 @@ let QueueWorkerExplorerService = class QueueWorkerExplorerService {
33
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
+ if (args.enabled === false) {
37
+ continue;
38
+ }
36
39
  for (const name of args.names) {
37
40
  metadata.push({
38
41
  instance: classInstanceWrapper.instance,
@@ -49,9 +52,12 @@ let QueueWorkerExplorerService = class QueueWorkerExplorerService {
49
52
  const metadata = [];
50
53
  const instance = worker.instance;
51
54
  const prototype = Object.getPrototypeOf(instance);
52
- for (const methodName of this.metadataScanner.getAllFilteredMethodNames(prototype)) {
55
+ for (const methodName of this.metadataScanner.getAllMethodNames(prototype)) {
53
56
  const args = Reflect.getMetadata(constants_1.QUEUE_WORKER_PROCESS_DECORATOR, prototype[methodName]);
54
57
  if (args) {
58
+ if (args.enabled === false) {
59
+ continue;
60
+ }
55
61
  metadata.push({
56
62
  priority: args.priority || 0,
57
63
  processor: prototype[methodName].bind(instance),
@@ -64,5 +70,6 @@ let QueueWorkerExplorerService = class QueueWorkerExplorerService {
64
70
  exports.QueueWorkerExplorerService = QueueWorkerExplorerService;
65
71
  exports.QueueWorkerExplorerService = QueueWorkerExplorerService = __decorate([
66
72
  (0, common_1.Injectable)(),
67
- __metadata("design:paramtypes", [core_1.DiscoveryService, metadata_scanner_1.MetadataScanner])
73
+ __metadata("design:paramtypes", [core_1.DiscoveryService,
74
+ metadata_scanner_1.MetadataScanner])
68
75
  ], QueueWorkerExplorerService);
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { ALL_WORKERS_QUEUE_WORKER_NAME as ALL_QUEUE_WORKERS, UNHANDLED_QUEUE_WORKER_NAME as UNHANDLED_QUEUE_WORKER, } from "./constants";
2
2
  export { QueueWorker, QueueWorkerProcess } from "./decorators";
3
- export { QueueWorkerModuleAsyncOptions, QueueWorkerModuleOptions, QueueWorkerModuleOptionsFactory, QueueWorkerProcessor, QueueWorkerProcessorStatus, QueueWorkerExtraConfig, QueueWorkerRawMessage, QueueWorkerControllerInterface, QueueWorkerControllerMetadata, QueueWorkerReceivedMessage, QueueWorkerDecodedMessage, } from "./interfaces";
3
+ export { QueueWorkerControllerInterface, QueueWorkerControllerMetadata, QueueWorkerDecodedMessage, QueueWorkerExtraConfig, QueueWorkerModuleAsyncOptions, QueueWorkerModuleOptions, QueueWorkerModuleOptionsFactory, QueueWorkerOptions, QueueWorkerProcessOptions, QueueWorkerProcessor, QueueWorkerProcessorStatus, QueueWorkerRawMessage, QueueWorkerReceivedMessage, } from "./interfaces";
4
4
  export { QueueWorkerModule } from "./worker.module";
5
5
  export { QueueWorkerService } from "./worker.service";
@@ -1,4 +1,4 @@
1
- import { QueueWorkerName, ModuleAsyncOptions, ModuleOptions, ModuleOptionsFactory, Message } from "@anchan828/nest-cloud-run-queue-common";
1
+ import { Message, ModuleAsyncOptions, ModuleOptions, ModuleOptionsFactory, QueueWorkerName } from "@anchan828/nest-cloud-run-queue-common";
2
2
  import { RequestMappingMetadata } from "@nestjs/common";
3
3
  import { Injectable } from "@nestjs/common/interfaces";
4
4
  export interface QueueWorkerModuleOptions extends ModuleOptions {
@@ -61,6 +61,10 @@ export interface QueueWorkerDecoratorArgs {
61
61
  * @memberof QueueWorkerDecoratorArgs
62
62
  */
63
63
  priority: number;
64
+ /**
65
+ * If you want to disable the worker, set it to false.
66
+ */
67
+ enabled?: boolean;
64
68
  }
65
69
  export interface QueueWorkerProcessDecoratorArgs {
66
70
  /**
@@ -70,6 +74,10 @@ export interface QueueWorkerProcessDecoratorArgs {
70
74
  * @memberof QueueWorkerProcessDecoratorArgs
71
75
  */
72
76
  priority: number;
77
+ /**
78
+ * If you want to disable the process, set it to false.
79
+ */
80
+ enabled?: boolean;
73
81
  }
74
82
  export type QueueWorkerRawMessage<T = any> = {
75
83
  readonly data?: string | null | Message<T>;
@@ -95,3 +103,27 @@ export interface QueueWorkerControllerMetadata extends RequestMappingMetadata {
95
103
  export interface QueueWorkerControllerInterface {
96
104
  execute(body: QueueWorkerReceivedMessage, headers: Record<string, string>): Promise<void>;
97
105
  }
106
+ export interface QueueWorkerOptions {
107
+ /**
108
+ * Worker name. If you want to define multiple names, use an array.
109
+ */
110
+ name: QueueWorkerName | QueueWorkerName[];
111
+ /**
112
+ * Highest priority is 0, and lower the larger integer you use.
113
+ */
114
+ priority?: number;
115
+ /**
116
+ * If you want to disable the worker, set it to false.
117
+ */
118
+ enabled?: boolean;
119
+ }
120
+ export interface QueueWorkerProcessOptions {
121
+ /**
122
+ * Highest priority is 0, and lower the larger integer you use.
123
+ */
124
+ priority?: number;
125
+ /**
126
+ * If you want to disable the process, set it to false.
127
+ */
128
+ enabled?: boolean;
129
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anchan828/nest-cloud-run-queue-worker",
3
- "version": "2.2.0",
3
+ "version": "2.2.1",
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.2.0"
36
+ "@anchan828/nest-cloud-run-queue-common": "^2.2.1"
37
37
  },
38
38
  "devDependencies": {
39
- "@nestjs/common": "10.3.9",
39
+ "@nestjs/common": "10.3.10",
40
40
  "rxjs": "7.8.1"
41
41
  },
42
42
  "peerDependencies": {
@@ -46,5 +46,5 @@
46
46
  "access": "public"
47
47
  },
48
48
  "packageManager": "npm@10.8.1",
49
- "gitHead": "9e50ec5859b0fb64fbcd5c19f3d13605d22850c8"
49
+ "gitHead": "882db718c2c146c2ec24b95462eccbad2cad2125"
50
50
  }