@remit/queue-sidecar 0.0.15 → 0.1.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.
- package/package.json +1 -1
- package/src/store.test.ts +0 -1
- package/src/store.ts +21 -18
package/package.json
CHANGED
package/src/store.test.ts
CHANGED
package/src/store.ts
CHANGED
|
@@ -53,8 +53,6 @@ const releaseRedrive = sqliteTable("release_redrive", {
|
|
|
53
53
|
release: text("release").notNull(),
|
|
54
54
|
});
|
|
55
55
|
|
|
56
|
-
const schema = { queues, messages, dedup, releaseRedrive };
|
|
57
|
-
|
|
58
56
|
export interface QueueDefinition {
|
|
59
57
|
readonly name: string;
|
|
60
58
|
readonly fifo: boolean;
|
|
@@ -130,8 +128,8 @@ const toQueueRecord = (row: QueueRow): QueueRecord => ({
|
|
|
130
128
|
* here so the behaviour is testable without a running HTTP server.
|
|
131
129
|
*/
|
|
132
130
|
export class QueueStore {
|
|
133
|
-
private readonly handle: SqliteHandle
|
|
134
|
-
private readonly db: SqliteHandle
|
|
131
|
+
private readonly handle: SqliteHandle;
|
|
132
|
+
private readonly db: SqliteHandle["db"];
|
|
135
133
|
private sequenceCounter: bigint;
|
|
136
134
|
private readonly startedAt = Date.now();
|
|
137
135
|
private readonly lastReceiveAt = new Map<string, number>();
|
|
@@ -146,7 +144,6 @@ export class QueueStore {
|
|
|
146
144
|
filename,
|
|
147
145
|
mode: "create",
|
|
148
146
|
synchronous: "FULL",
|
|
149
|
-
schema,
|
|
150
147
|
});
|
|
151
148
|
this.db = this.handle.db;
|
|
152
149
|
this.migrate();
|
|
@@ -508,6 +505,15 @@ export class QueueStore {
|
|
|
508
505
|
* a FIFO group still sees it after anything sent since.
|
|
509
506
|
*/
|
|
510
507
|
redriveDeadLetters(deadLetterName: string, now = Date.now()): number {
|
|
508
|
+
return this.db.transaction(
|
|
509
|
+
(): number => this.moveDeadLetters(deadLetterName, now),
|
|
510
|
+
IMMEDIATE,
|
|
511
|
+
);
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
// The body of a redrive, for a caller already inside a transaction:
|
|
515
|
+
// node:sqlite cannot begin one inside another.
|
|
516
|
+
private moveDeadLetters(deadLetterName: string, now: number): number {
|
|
511
517
|
this.requireQueue(deadLetterName);
|
|
512
518
|
const source = this.listQueues().find(
|
|
513
519
|
(queue) => queue.deadLetterTargetName === deadLetterName,
|
|
@@ -517,18 +523,14 @@ export class QueueStore {
|
|
|
517
523
|
`${deadLetterName} is not the dead-letter queue of any queue`,
|
|
518
524
|
);
|
|
519
525
|
}
|
|
520
|
-
const
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
.all();
|
|
529
|
-
for (const row of rows) this.moveToQueue(row, destination, now);
|
|
530
|
-
return rows.length;
|
|
531
|
-
}, IMMEDIATE);
|
|
526
|
+
const rows = this.db
|
|
527
|
+
.select()
|
|
528
|
+
.from(messages)
|
|
529
|
+
.where(eq(messages.queueName, deadLetterName))
|
|
530
|
+
.orderBy(asc(messages.id))
|
|
531
|
+
.all();
|
|
532
|
+
for (const row of rows) this.moveToQueue(row, source.name, now);
|
|
533
|
+
return rows.length;
|
|
532
534
|
}
|
|
533
535
|
|
|
534
536
|
redriveForRelease(release: string, deadLetterNames: string[]): void {
|
|
@@ -539,7 +541,8 @@ export class QueueStore {
|
|
|
539
541
|
.where(eq(releaseRedrive.id, 1))
|
|
540
542
|
.get();
|
|
541
543
|
if (marker?.release === release) return;
|
|
542
|
-
|
|
544
|
+
const now = Date.now();
|
|
545
|
+
for (const name of deadLetterNames) this.moveDeadLetters(name, now);
|
|
543
546
|
this.db
|
|
544
547
|
.insert(releaseRedrive)
|
|
545
548
|
.values({ id: 1, release })
|