anbaric-cloud-hosting 1.21.2 → 1.21.3
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.
|
@@ -6,8 +6,18 @@ class Dispatcher {
|
|
|
6
6
|
private ticker? : NodeJS.Timeout;
|
|
7
7
|
private draining = false;
|
|
8
8
|
|
|
9
|
+
/* A confirmable queue leases each dequeued message and redelivers any it is
|
|
10
|
+
not `confirm`ed (the consumer confirms once it has processed it). So the
|
|
11
|
+
dispatcher must NOT put unroutable or failed messages back — the leased
|
|
12
|
+
row already redelivers, and re-enqueuing would add a fresh duplicate on
|
|
13
|
+
every tick, growing the queue without bound. A plain queue removes on
|
|
14
|
+
dequeue, so there those messages must be re-enqueued to be retried. */
|
|
15
|
+
private readonly redelivers : boolean;
|
|
16
|
+
|
|
9
17
|
constructor(private queue : Dequeue, private registry : ConsumerRegistry,
|
|
10
|
-
private dispatchIntervalMs : number = 1000) {
|
|
18
|
+
private dispatchIntervalMs : number = 1000) {
|
|
19
|
+
this.redelivers = typeof (this.queue as { confirm? : unknown }).confirm === "function";
|
|
20
|
+
}
|
|
11
21
|
|
|
12
22
|
start() : void {
|
|
13
23
|
if (this.ticker) return;
|
|
@@ -21,8 +31,10 @@ class Dispatcher {
|
|
|
21
31
|
}
|
|
22
32
|
|
|
23
33
|
private async drain() : Promise<void> {
|
|
34
|
+
|
|
24
35
|
if (this.draining) return;
|
|
25
36
|
this.draining = true;
|
|
37
|
+
|
|
26
38
|
try {
|
|
27
39
|
const messages = await this.queue.dequeueSome();
|
|
28
40
|
const byConsumerUrl = new Map<string, Array<QueueMessage>>();
|
|
@@ -30,7 +42,7 @@ class Dispatcher {
|
|
|
30
42
|
for (const message of messages) {
|
|
31
43
|
const url = this.registry.lookup(message.appId, message.workflowId);
|
|
32
44
|
if (!url) {
|
|
33
|
-
await this.queue.enqueue(message.jobId, message.appId, message.workflowId);
|
|
45
|
+
if (!this.redelivers) await this.queue.enqueue(message.jobId, message.appId, message.workflowId);
|
|
34
46
|
continue;
|
|
35
47
|
}
|
|
36
48
|
byConsumerUrl.set(url, [...(byConsumerUrl.get(url) ?? []), message]);
|
|
@@ -53,8 +65,10 @@ class Dispatcher {
|
|
|
53
65
|
});
|
|
54
66
|
if (!response.ok) throw new Error(`Consumer at ${url} responded with status ${response.status}`);
|
|
55
67
|
} catch {
|
|
56
|
-
|
|
57
|
-
|
|
68
|
+
if (!this.redelivers) {
|
|
69
|
+
for (const message of batch) {
|
|
70
|
+
await this.queue.enqueue(message.jobId, message.appId, message.workflowId);
|
|
71
|
+
}
|
|
58
72
|
}
|
|
59
73
|
}
|
|
60
74
|
}
|