@anchan828/nest-cloud-run-queue-worker 2.1.18 → 2.2.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/util.d.ts +2 -0
- package/dist/util.js +45 -0
- package/dist/worker.controller.js +1 -0
- package/dist/worker.service.d.ts +9 -5
- package/dist/worker.service.js +7 -44
- package/package.json +4 -4
package/dist/util.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Message } from "@anchan828/nest-cloud-run-queue-common";
|
|
2
|
+
import { QueueWorkerDecodedMessage, QueueWorkerRawMessage } from "./interfaces";
|
|
2
3
|
/**
|
|
3
4
|
* parse json string to javascript object.
|
|
4
5
|
* JSON.parse has receiver for Date.parse.
|
|
@@ -24,3 +25,4 @@ export declare function sortByPriority<T extends {
|
|
|
24
25
|
* @return {*} {boolean}
|
|
25
26
|
*/
|
|
26
27
|
export declare function isBase64(value?: string | null | Message): value is string;
|
|
28
|
+
export declare function decodeMessage<T = any>(message: QueueWorkerRawMessage | Message): QueueWorkerDecodedMessage<T>;
|
package/dist/util.js
CHANGED
|
@@ -3,6 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.parseJSON = void 0;
|
|
4
4
|
exports.sortByPriority = sortByPriority;
|
|
5
5
|
exports.isBase64 = isBase64;
|
|
6
|
+
exports.decodeMessage = decodeMessage;
|
|
7
|
+
const common_1 = require("@nestjs/common");
|
|
8
|
+
const constants_1 = require("./constants");
|
|
6
9
|
const dateRegExp = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/;
|
|
7
10
|
/**
|
|
8
11
|
* parse json string to javascript object.
|
|
@@ -57,3 +60,45 @@ function isBase64(value) {
|
|
|
57
60
|
const firstPaddingChar = value.indexOf("=");
|
|
58
61
|
return (firstPaddingChar === -1 || firstPaddingChar === len - 1 || (firstPaddingChar === len - 2 && value[len - 1] === "="));
|
|
59
62
|
}
|
|
63
|
+
function decodeMessage(message) {
|
|
64
|
+
let data;
|
|
65
|
+
if (isBase64(message.data)) {
|
|
66
|
+
// pubsub
|
|
67
|
+
data = decodeData(message.data);
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
// tasks / http
|
|
71
|
+
data = message;
|
|
72
|
+
}
|
|
73
|
+
if (!data.name) {
|
|
74
|
+
throw new common_1.BadRequestException(constants_1.ERROR_QUEUE_WORKER_NAME_NOT_FOUND);
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
data,
|
|
78
|
+
headers: "headers" in message ? message.headers : undefined,
|
|
79
|
+
raw: message,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
function decodeData(data) {
|
|
83
|
+
if (!data) {
|
|
84
|
+
throw new common_1.BadRequestException(constants_1.ERROR_INVALID_MESSAGE_FORMAT);
|
|
85
|
+
}
|
|
86
|
+
if (Buffer.isBuffer(data)) {
|
|
87
|
+
data = data.toString();
|
|
88
|
+
}
|
|
89
|
+
if (data instanceof Uint8Array) {
|
|
90
|
+
data = new TextDecoder("utf8").decode(data);
|
|
91
|
+
}
|
|
92
|
+
if (isBase64(data)) {
|
|
93
|
+
data = Buffer.from(data, "base64").toString();
|
|
94
|
+
}
|
|
95
|
+
try {
|
|
96
|
+
if (typeof data === "string") {
|
|
97
|
+
return (0, exports.parseJSON)(data);
|
|
98
|
+
}
|
|
99
|
+
return data;
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
throw new common_1.BadRequestException(constants_1.ERROR_INVALID_MESSAGE_FORMAT);
|
|
103
|
+
}
|
|
104
|
+
}
|
package/dist/worker.service.d.ts
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
import { Logger } from "@nestjs/common";
|
|
2
|
-
import {
|
|
2
|
+
import { Message } from "@anchan828/nest-cloud-run-queue-common";
|
|
3
3
|
import { QueueWorkerExplorerService } from "./explorer.service";
|
|
4
|
-
import { QueueWorkerRawMessage } from "./interfaces";
|
|
4
|
+
import { QueueWorkerDecodedMessage, QueueWorkerModuleOptions, QueueWorkerRawMessage } from "./interfaces";
|
|
5
5
|
export declare class QueueWorkerService {
|
|
6
6
|
#private;
|
|
7
7
|
private readonly options;
|
|
8
8
|
private readonly logger;
|
|
9
9
|
private readonly explorerService;
|
|
10
10
|
constructor(options: QueueWorkerModuleOptions, logger: Logger, explorerService: QueueWorkerExplorerService);
|
|
11
|
-
execute(
|
|
12
|
-
|
|
11
|
+
execute<T = any>(meessage: Message<T>): Promise<void>;
|
|
12
|
+
execute<T = any>(meessage: QueueWorkerDecodedMessage<T>): Promise<void>;
|
|
13
|
+
execute<T = any>(meessage: QueueWorkerRawMessage<T>): Promise<void>;
|
|
14
|
+
/**
|
|
15
|
+
* @deprecated Use `decodeMessage` function instead.
|
|
16
|
+
*/
|
|
17
|
+
decodeMessage<T = any>(message: QueueWorkerRawMessage | Message): QueueWorkerDecodedMessage<T>;
|
|
13
18
|
private runWorkers;
|
|
14
19
|
private isDecodedMessage;
|
|
15
|
-
private decodeData;
|
|
16
20
|
private execProcessor;
|
|
17
21
|
}
|
package/dist/worker.service.js
CHANGED
|
@@ -38,28 +38,14 @@ let QueueWorkerService = class QueueWorkerService {
|
|
|
38
38
|
this.explorerService = explorerService;
|
|
39
39
|
_QueueWorkerService__allWorkers.set(this, void 0);
|
|
40
40
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
await this.runWorkers(this.isDecodedMessage(rawMessage) ? rawMessage : this.decodeMessage(rawMessage));
|
|
41
|
+
async execute(meessage) {
|
|
42
|
+
await this.runWorkers(this.isDecodedMessage(meessage) ? meessage : (0, util_1.decodeMessage)(meessage));
|
|
44
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* @deprecated Use `decodeMessage` function instead.
|
|
46
|
+
*/
|
|
45
47
|
decodeMessage(message) {
|
|
46
|
-
|
|
47
|
-
if ((0, util_1.isBase64)(message.data)) {
|
|
48
|
-
// pubsub
|
|
49
|
-
data = this.decodeData(message.data);
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
// tasks / http
|
|
53
|
-
data = message;
|
|
54
|
-
}
|
|
55
|
-
if (!data.name) {
|
|
56
|
-
throw new common_1.BadRequestException(constants_1.ERROR_QUEUE_WORKER_NAME_NOT_FOUND);
|
|
57
|
-
}
|
|
58
|
-
return {
|
|
59
|
-
data,
|
|
60
|
-
headers: message.headers,
|
|
61
|
-
raw: message,
|
|
62
|
-
};
|
|
48
|
+
return (0, util_1.decodeMessage)(message);
|
|
63
49
|
}
|
|
64
50
|
async runWorkers(decodedMessage) {
|
|
65
51
|
const maxRetryAttempts = this.options.maxRetryAttempts ?? 1;
|
|
@@ -86,30 +72,7 @@ let QueueWorkerService = class QueueWorkerService {
|
|
|
86
72
|
await this.options.extraConfig?.postProcessor?.(decodedMessage.data.name, decodedMessage.data.data, decodedMessage.raw);
|
|
87
73
|
}
|
|
88
74
|
isDecodedMessage(message) {
|
|
89
|
-
return
|
|
90
|
-
}
|
|
91
|
-
decodeData(data) {
|
|
92
|
-
if (!data) {
|
|
93
|
-
throw new common_1.BadRequestException(constants_1.ERROR_INVALID_MESSAGE_FORMAT);
|
|
94
|
-
}
|
|
95
|
-
if (Buffer.isBuffer(data)) {
|
|
96
|
-
data = data.toString();
|
|
97
|
-
}
|
|
98
|
-
if (data instanceof Uint8Array) {
|
|
99
|
-
data = new TextDecoder("utf8").decode(data);
|
|
100
|
-
}
|
|
101
|
-
if ((0, util_1.isBase64)(data)) {
|
|
102
|
-
data = Buffer.from(data, "base64").toString();
|
|
103
|
-
}
|
|
104
|
-
try {
|
|
105
|
-
if (typeof data === "string") {
|
|
106
|
-
return (0, util_1.parseJSON)(data);
|
|
107
|
-
}
|
|
108
|
-
return data;
|
|
109
|
-
}
|
|
110
|
-
catch {
|
|
111
|
-
throw new common_1.BadRequestException(constants_1.ERROR_INVALID_MESSAGE_FORMAT);
|
|
112
|
-
}
|
|
75
|
+
return "raw" in message;
|
|
113
76
|
}
|
|
114
77
|
async execProcessor(processor, maxRetryAttempts, data, raw) {
|
|
115
78
|
for (let i = 0; i < maxRetryAttempts; i++) {
|
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.2.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,7 +33,7 @@
|
|
|
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.2.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@nestjs/common": "10.3.9",
|
|
@@ -45,6 +45,6 @@
|
|
|
45
45
|
"publishConfig": {
|
|
46
46
|
"access": "public"
|
|
47
47
|
},
|
|
48
|
-
"packageManager": "npm@10.
|
|
49
|
-
"gitHead": "
|
|
48
|
+
"packageManager": "npm@10.8.1",
|
|
49
|
+
"gitHead": "9e50ec5859b0fb64fbcd5c19f3d13605d22850c8"
|
|
50
50
|
}
|