prime-sdk 3.0.2 → 3.0.4
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/.vscode/settings.json +3 -0
- package/dist/external/aws/sqs/sqs.service.d.ts +1 -0
- package/dist/external/aws/sqs/sqs.service.js +3 -0
- package/dist/external/aws/sqs/sqs.service.js.map +1 -1
- package/dist/lib/queue/interfaces/queue.interface.d.ts +1 -0
- package/dist/lib/queue/interfaces/queue.interface.js.map +1 -1
- package/dist/lib/queue/queue.d.ts +6 -0
- package/dist/lib/queue/queue.js +41 -11
- package/dist/lib/queue/queue.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/external/aws/sqs/sqs.service.ts +4 -0
- package/src/lib/queue/interfaces/queue.interface.ts +1 -0
- package/src/lib/queue/queue.ts +53 -13
- package/.yarn/install-state.gz +0 -0
- package/.yarnrc.yml +0 -1
package/package.json
CHANGED
|
@@ -5,6 +5,7 @@ export interface IQueue {
|
|
|
5
5
|
receiveMessages(): Promise<ReceiveMessageResult>;
|
|
6
6
|
receiveMessagesV2(): Promise<ReceiveMessageResult>;
|
|
7
7
|
setup({ waitTimeSeconds, bulk, queueUrl, attributeNames }): void;
|
|
8
|
+
destroyClient(): void;
|
|
8
9
|
}
|
|
9
10
|
|
|
10
11
|
export const IQueue = Symbol('IQueue');
|
package/src/lib/queue/queue.ts
CHANGED
|
@@ -16,7 +16,15 @@ export class Queue {
|
|
|
16
16
|
|
|
17
17
|
private context: IConsumer = null;
|
|
18
18
|
|
|
19
|
-
private
|
|
19
|
+
private processing: number = 0;
|
|
20
|
+
|
|
21
|
+
private readonly MAX_TIME_TO_WAIT_FOR_PROCESSING = 20000;
|
|
22
|
+
|
|
23
|
+
private stopped: boolean = false;
|
|
24
|
+
|
|
25
|
+
private abortController: AbortController = null;
|
|
26
|
+
|
|
27
|
+
private inWork: boolean = true;
|
|
20
28
|
|
|
21
29
|
private waitTimeSeconds: number = 20;
|
|
22
30
|
|
|
@@ -40,6 +48,10 @@ export class Queue {
|
|
|
40
48
|
this.waitTimeSeconds = waitTimeSeconds;
|
|
41
49
|
this.attributeNames = attributeNames;
|
|
42
50
|
this.version = version;
|
|
51
|
+
this.abortController = new AbortController();
|
|
52
|
+
this.stopped = false;
|
|
53
|
+
this.processing = 0;
|
|
54
|
+
this.inWork = true;
|
|
43
55
|
|
|
44
56
|
this.broker.setup({
|
|
45
57
|
waitTimeSeconds: this.waitTimeSeconds,
|
|
@@ -48,19 +60,24 @@ export class Queue {
|
|
|
48
60
|
attributeNames: this.attributeNames,
|
|
49
61
|
});
|
|
50
62
|
|
|
51
|
-
while (
|
|
63
|
+
while (this.inWork) {
|
|
52
64
|
await this.run(version);
|
|
53
65
|
}
|
|
54
66
|
}
|
|
55
67
|
|
|
56
68
|
async run(version: number) {
|
|
57
|
-
this.
|
|
58
|
-
|
|
59
|
-
const response = await this.receiveMessages(version);
|
|
69
|
+
this.processing += 1;
|
|
60
70
|
|
|
61
71
|
try {
|
|
72
|
+
const response = await this.receiveMessages(version);
|
|
73
|
+
const messages = response.Messages;
|
|
74
|
+
|
|
75
|
+
if (!messages) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
|
|
62
79
|
if (this.bulk === 1) {
|
|
63
|
-
const message =
|
|
80
|
+
const message = messages?.[0] || null;
|
|
64
81
|
|
|
65
82
|
if (message) {
|
|
66
83
|
await this.context.handleMessage(message);
|
|
@@ -68,20 +85,21 @@ export class Queue {
|
|
|
68
85
|
await this.deleteMessage(message.ReceiptHandle);
|
|
69
86
|
}
|
|
70
87
|
|
|
71
|
-
this.inWork = false;
|
|
72
|
-
|
|
73
88
|
return;
|
|
74
89
|
}
|
|
75
90
|
|
|
76
|
-
await this.context.handleMessage(
|
|
91
|
+
await this.context.handleMessage(messages);
|
|
77
92
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
93
|
+
await Promise.all(
|
|
94
|
+
messages.map((message: Message) =>
|
|
95
|
+
this.deleteMessage(message.ReceiptHandle),
|
|
96
|
+
),
|
|
97
|
+
);
|
|
81
98
|
} catch (error) {
|
|
82
99
|
await this.context.handleError(error);
|
|
100
|
+
} finally {
|
|
101
|
+
this.processing -= 1;
|
|
83
102
|
}
|
|
84
|
-
this.inWork = false;
|
|
85
103
|
}
|
|
86
104
|
|
|
87
105
|
async receiveMessages(version: number): Promise<ReceiveMessageResult> {
|
|
@@ -95,4 +113,26 @@ export class Queue {
|
|
|
95
113
|
async deleteMessage(receiptHandle): Promise<unknown> {
|
|
96
114
|
return await this.broker.deleteMessage(receiptHandle);
|
|
97
115
|
}
|
|
116
|
+
|
|
117
|
+
async stop(): Promise<void> {
|
|
118
|
+
if (this.stopped) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
const timeMax = new Date().getTime() + this.MAX_TIME_TO_WAIT_FOR_PROCESSING;
|
|
122
|
+
|
|
123
|
+
this.inWork = false;
|
|
124
|
+
this.stopped = true;
|
|
125
|
+
this.abortController?.abort();
|
|
126
|
+
|
|
127
|
+
while (this.processing > 0) {
|
|
128
|
+
const time = new Date().getTime();
|
|
129
|
+
if (time >= timeMax) break;
|
|
130
|
+
await this.sleep(500);
|
|
131
|
+
}
|
|
132
|
+
this.broker.destroyClient();
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
private sleep(ms: number) {
|
|
136
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
137
|
+
}
|
|
98
138
|
}
|
package/.yarn/install-state.gz
DELETED
|
Binary file
|
package/.yarnrc.yml
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
nodeLinker: node-modules
|