@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remit/queue-sidecar",
3
- "version": "0.0.15",
3
+ "version": "0.1.1",
4
4
  "type": "module",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
package/src/store.test.ts CHANGED
@@ -326,7 +326,6 @@ describe("QueueStore", () => {
326
326
  filename: path,
327
327
  mode: "open",
328
328
  synchronous: "FULL",
329
- schema: {},
330
329
  });
331
330
  seed.sqlite
332
331
  .prepare(
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<typeof schema>;
134
- private readonly db: SqliteHandle<typeof schema>["db"];
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 destination = source.name;
521
-
522
- return this.db.transaction((): number => {
523
- const rows = this.db
524
- .select()
525
- .from(messages)
526
- .where(eq(messages.queueName, deadLetterName))
527
- .orderBy(asc(messages.id))
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
- for (const name of deadLetterNames) this.redriveDeadLetters(name);
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 })