@anchan828/nest-cloud-run-queue-worker 2.2.0 → 2.3.0
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.
- package/dist/decorators.d.ts +3 -0
- package/dist/decorators.js +21 -12
- package/dist/explorer.service.js +9 -2
- package/dist/index.d.ts +1 -1
- package/dist/interfaces.d.ts +51 -1
- package/dist/worker.service.js +1 -0
- package/package.json +4 -4
package/dist/decorators.d.ts
CHANGED
|
@@ -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;
|
package/dist/decorators.js
CHANGED
|
@@ -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(
|
|
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
|
-
|
|
10
|
-
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
}
|
package/dist/explorer.service.js
CHANGED
|
@@ -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.
|
|
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,
|
|
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,
|
|
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";
|
package/dist/interfaces.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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 {
|
|
@@ -51,6 +51,24 @@ export declare enum QueueWorkerProcessorStatus {
|
|
|
51
51
|
export type QueueWorkerExtraConfig = {
|
|
52
52
|
preProcessor?: (name: string, ...args: Parameters<QueueWorkerProcessor>) => (QueueWorkerProcessorStatus | undefined | void) | Promise<QueueWorkerProcessorStatus | undefined | void>;
|
|
53
53
|
postProcessor?: (name: string, ...args: Parameters<QueueWorkerProcessor>) => void | Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Exceptions thrown in the processor do not reach the top level and are not detected by the application. If you want to do something with processor exceptions, use this property.
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* catchProcessorException: (error: Error) => {
|
|
59
|
+
* captureException(error); // Sentry
|
|
60
|
+
* }
|
|
61
|
+
* ```
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```ts
|
|
65
|
+
* catchProcessorException: async (error: Error) => {
|
|
66
|
+
* // You can throw errors and let them reach the top level. Use an ExceptionFilter or similar to handle them appropriately.
|
|
67
|
+
* throw error;
|
|
68
|
+
* }
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
catchProcessorException?: <T extends Error = Error>(error: T, raw: QueueWorkerRawMessage) => void | Promise<void>;
|
|
54
72
|
};
|
|
55
73
|
export interface QueueWorkerDecoratorArgs {
|
|
56
74
|
names: QueueWorkerName[];
|
|
@@ -61,6 +79,10 @@ export interface QueueWorkerDecoratorArgs {
|
|
|
61
79
|
* @memberof QueueWorkerDecoratorArgs
|
|
62
80
|
*/
|
|
63
81
|
priority: number;
|
|
82
|
+
/**
|
|
83
|
+
* If you want to disable the worker, set it to false. Defaults to true.
|
|
84
|
+
*/
|
|
85
|
+
enabled?: boolean;
|
|
64
86
|
}
|
|
65
87
|
export interface QueueWorkerProcessDecoratorArgs {
|
|
66
88
|
/**
|
|
@@ -70,6 +92,10 @@ export interface QueueWorkerProcessDecoratorArgs {
|
|
|
70
92
|
* @memberof QueueWorkerProcessDecoratorArgs
|
|
71
93
|
*/
|
|
72
94
|
priority: number;
|
|
95
|
+
/**
|
|
96
|
+
* If you want to disable the process, set it to false. Defaults to true.
|
|
97
|
+
*/
|
|
98
|
+
enabled?: boolean;
|
|
73
99
|
}
|
|
74
100
|
export type QueueWorkerRawMessage<T = any> = {
|
|
75
101
|
readonly data?: string | null | Message<T>;
|
|
@@ -95,3 +121,27 @@ export interface QueueWorkerControllerMetadata extends RequestMappingMetadata {
|
|
|
95
121
|
export interface QueueWorkerControllerInterface {
|
|
96
122
|
execute(body: QueueWorkerReceivedMessage, headers: Record<string, string>): Promise<void>;
|
|
97
123
|
}
|
|
124
|
+
export interface QueueWorkerOptions {
|
|
125
|
+
/**
|
|
126
|
+
* Worker name. If you want to define multiple names, use an array.
|
|
127
|
+
*/
|
|
128
|
+
name: QueueWorkerName | QueueWorkerName[];
|
|
129
|
+
/**
|
|
130
|
+
* Highest priority is 0, and lower the larger integer you use.
|
|
131
|
+
*/
|
|
132
|
+
priority?: number;
|
|
133
|
+
/**
|
|
134
|
+
* If you want to disable the worker, set it to false. Defaults to true.
|
|
135
|
+
*/
|
|
136
|
+
enabled?: boolean;
|
|
137
|
+
}
|
|
138
|
+
export interface QueueWorkerProcessOptions {
|
|
139
|
+
/**
|
|
140
|
+
* Highest priority is 0, and lower the larger integer you use.
|
|
141
|
+
*/
|
|
142
|
+
priority?: number;
|
|
143
|
+
/**
|
|
144
|
+
* If you want to disable the process, set it to false. Defaults to true.
|
|
145
|
+
*/
|
|
146
|
+
enabled?: boolean;
|
|
147
|
+
}
|
package/dist/worker.service.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anchan828/nest-cloud-run-queue-worker",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
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.
|
|
36
|
+
"@anchan828/nest-cloud-run-queue-common": "^2.3.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@nestjs/common": "10.3.
|
|
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": "
|
|
49
|
+
"gitHead": "24cf62975961ff44cd62d00128a7510a771a4e8f"
|
|
50
50
|
}
|