@happyvertical/smrt-jobs 0.61.3 → 0.61.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.
@@ -1,11 +1,9 @@
1
- import { getDatabase } from '@happyvertical/sql';
2
- /**
3
- * Configuration for an off-loop liveness ticker (passed via `workerData`).
4
- */
5
- export interface LivenessTickerOptions {
6
- /** Database URL the owning runner is using. */
1
+ import { getDatabase, type ReopenOptions, type DatabaseEngine as SqlEngine } from '@happyvertical/sql';
2
+ /** Options common to every engine. */
3
+ interface LivenessTickerBaseOptions {
4
+ /** Database URL the owning runner is using (PostgreSQL only). */
7
5
  url: string;
8
- /** Optional explicit engine/type hint. */
6
+ /** Optional explicit engine/type hint (PostgreSQL only). */
9
7
  type?: string;
10
8
  /** This runner incarnation's worker key (the `_smrt_workers.worker_id`). */
11
9
  workerKey: string;
@@ -16,6 +14,22 @@ export interface LivenessTickerOptions {
16
14
  /** Queues the runner polls, re-written on every renewal. */
17
15
  queues?: string[];
18
16
  }
17
+ /**
18
+ * Configuration for an off-loop liveness ticker (passed via `workerData`).
19
+ *
20
+ * SQLite connects only through `reopen` (from the runtime connection's
21
+ * `db.reopenOptions()`) together with the `expectedEngine` that connection
22
+ * reported; the thread refuses to run on a different engine. Without `reopen`
23
+ * only PostgreSQL may be reached, from `url`.
24
+ */
25
+ export type LivenessTickerOptions = LivenessTickerBaseOptions & ({
26
+ reopen: ReopenOptions;
27
+ /** The engine the runner's connection reported; required with `reopen`. */
28
+ expectedEngine: SqlEngine;
29
+ } | {
30
+ reopen?: undefined;
31
+ expectedEngine?: undefined;
32
+ });
19
33
  export interface LivenessTicker {
20
34
  /** Stop renewing and close the connection. */
21
35
  stop: () => Promise<void>;
@@ -31,7 +45,7 @@ export interface LivenessTicker {
31
45
  * be confused with — or resize — the application's pool for the same URL.
32
46
  * Other engines pass through unchanged.
33
47
  */
34
- export declare function livenessConnectionOptions(options: Pick<LivenessTickerOptions, 'url' | 'type'>): Parameters<typeof getDatabase>[0];
48
+ export declare function livenessConnectionOptions(options: Pick<LivenessTickerOptions, 'url' | 'type' | 'reopen'>): Parameters<typeof getDatabase>[0];
35
49
  /**
36
50
  * Renew a worker's liveness lease from *outside* the handler event loop.
37
51
  *
@@ -42,4 +56,5 @@ export declare function livenessConnectionOptions(options: Pick<LivenessTickerOp
42
56
  * lease expires within its TTL, which is how recovery detects death.
43
57
  */
44
58
  export declare function runLivenessTicker(options: LivenessTickerOptions): Promise<LivenessTicker>;
59
+ export {};
45
60
  //# sourceMappingURL=worker-liveness-ticker.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"worker-liveness-ticker.d.ts","sourceRoot":"","sources":["../src/worker-liveness-ticker.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAGjD;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,+CAA+C;IAC/C,GAAG,EAAE,MAAM,CAAC;IACZ,0CAA0C;IAC1C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,4EAA4E;IAC5E,SAAS,EAAE,MAAM,CAAC;IAClB,0CAA0C;IAC1C,UAAU,EAAE,MAAM,CAAC;IACnB,uCAAuC;IACvC,WAAW,EAAE,MAAM,CAAC;IACpB,4DAA4D;IAC5D,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,MAAM,WAAW,cAAc;IAC7B,8CAA8C;IAC9C,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3B;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,IAAI,CAAC,qBAAqB,EAAE,KAAK,GAAG,MAAM,CAAC,GACnD,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC,CAYnC;AAED;;;;;;;;GAQG;AACH,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,cAAc,CAAC,CAqEzB"}
1
+ {"version":3,"file":"worker-liveness-ticker.d.ts","sourceRoot":"","sources":["../src/worker-liveness-ticker.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,WAAW,EACX,KAAK,aAAa,EAClB,KAAK,cAAc,IAAI,SAAS,EACjC,MAAM,oBAAoB,CAAC;AAE5B,sCAAsC;AACtC,UAAU,yBAAyB;IACjC,iEAAiE;IACjE,GAAG,EAAE,MAAM,CAAC;IACZ,4DAA4D;IAC5D,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,4EAA4E;IAC5E,SAAS,EAAE,MAAM,CAAC;IAClB,0CAA0C;IAC1C,UAAU,EAAE,MAAM,CAAC;IACnB,uCAAuC;IACvC,WAAW,EAAE,MAAM,CAAC;IACpB,4DAA4D;IAC5D,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,qBAAqB,GAAG,yBAAyB,GAC3D,CACI;IACE,MAAM,EAAE,aAAa,CAAC;IACtB,2EAA2E;IAC3E,cAAc,EAAE,SAAS,CAAC;CAC3B,GACD;IAAE,MAAM,CAAC,EAAE,SAAS,CAAC;IAAC,cAAc,CAAC,EAAE,SAAS,CAAA;CAAE,CACrD,CAAC;AAEJ,MAAM,WAAW,cAAc;IAC7B,8CAA8C;IAC9C,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3B;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,IAAI,CAAC,qBAAqB,EAAE,KAAK,GAAG,MAAM,GAAG,QAAQ,CAAC,GAC9D,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC,CAmBnC;AAED;;;;;;;;GAQG;AACH,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,cAAc,CAAC,CAsFzB"}
@@ -1,5 +1,5 @@
1
1
  import { detectEngine } from '@happyvertical/smrt-core';
2
- import type { DatabaseInterface } from '@happyvertical/sql';
2
+ import type { DatabaseInterface, ReopenOptions, DatabaseEngine as SqlEngine } from '@happyvertical/sql';
3
3
  type DatabaseEngine = ReturnType<typeof detectEngine>;
4
4
  /** Mark a worker key as live in this process. */
5
5
  export declare function registerLiveWorker(workerKey: string): void;
@@ -59,13 +59,43 @@ export declare function resolveEngine(db: DatabaseInterface): DatabaseEngine;
59
59
  */
60
60
  export declare function isInMemory(db: DatabaseInterface): boolean;
61
61
  /**
62
- * Whether the off-loop liveness thread can run against this connection.
62
+ * How the off-loop liveness thread gets its database connection, or why it
63
+ * must not run.
63
64
  *
64
- * Requires a second independent connection to the same data: true for Postgres
65
- * and file-backed SQLite. In-memory SQLite cannot be reached from another
66
- * connection, and DuckDB is single-writer per file — both fall back to
67
- * main-loop lease renewal + the in-process live set.
65
+ * - `reopen`: file-backed SQLite whose connection can be reopened on the same
66
+ * engine (`db.engine` plus `db.reopenOptions()`). The thread opens exactly
67
+ * those options and checks that the engine it got is `engine`.
68
+ * - `url`: PostgreSQL, which has no second-engine hazard. The thread builds its
69
+ * own pooled connection from the URL, as it always has.
70
+ * - `none`: no safe second connection; the runner renews the lease on its own
71
+ * connection from the main loop and logs `reason` once.
72
+ *
73
+ * Two SQLite engines (`node:sqlite`, `@libsql/client`) hold their own copy of
74
+ * SQLite whose file locks do not coordinate, so a second connection on the
75
+ * other engine can corrupt a WAL file (#4978). A connection that does not say
76
+ * which engine it uses is treated as unsafe to share.
68
77
  */
69
- export declare function offLoopEligible(db: DatabaseInterface): boolean;
78
+ export type LivenessConnectionPlan = {
79
+ kind: 'reopen';
80
+ engine: SqlEngine;
81
+ reopen: ReopenOptions;
82
+ } | {
83
+ kind: 'url';
84
+ url: string;
85
+ type: string;
86
+ } | {
87
+ kind: 'none';
88
+ reason: string;
89
+ /**
90
+ * True where a liveness thread used to run and now cannot (file-backed
91
+ * SQLite without a same-engine connection, or secure SQLite on Windows).
92
+ * False for engines that never had a usable second connection
93
+ * (in-memory SQLite, DuckDB, JSON), where main-loop renewal is the
94
+ * long-standing design and not a degradation.
95
+ */
96
+ degraded: boolean;
97
+ };
98
+ /** Decide how (and whether) the liveness thread may open its connection. */
99
+ export declare function planLivenessConnection(db: DatabaseInterface, platform?: NodeJS.Platform): LivenessConnectionPlan;
70
100
  export {};
71
101
  //# sourceMappingURL=worker-liveness.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"worker-liveness.d.ts","sourceRoot":"","sources":["../src/worker-liveness.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAG5D,KAAK,cAAc,GAAG,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC;AAgDtD,iDAAiD;AACjD,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAE1D;AAED,wDAAwD;AACxD,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAE5D;AAED,oDAAoD;AACpD,wBAAgB,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAEvD;AAED,yDAAyD;AACzD,wBAAgB,cAAc,IAAI,GAAG,CAAC,MAAM,CAAC,CAE5C;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAC3B,SAAS,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EACpC,cAAc,EAAE,GAAG,CAAC,MAAM,CAAC,GAC1B,OAAO,CAGT;AAED;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEtD;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,EAAE,EAAE,iBAAiB,GAAG,MAAM,CAGxD;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,wBAAwB,CAC5C,EAAE,EAAE,iBAAiB,GACpB,OAAO,CAAC,IAAI,CAAC,CAOf;AAED,oDAAoD;AACpD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CASf;AAED,oDAAoD;AACpD,wBAAgB,aAAa,CAAC,EAAE,EAAE,iBAAiB,GAAG,cAAc,CAOnE;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,EAAE,EAAE,iBAAiB,GAAG,OAAO,CAOzD;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,sBAAsB,GAC9B;IACE,IAAI,EAAE,QAAQ,CAAC;IACf,MAAM,EAAE,SAAS,CAAC;IAClB,MAAM,EAAE,aAAa,CAAC;CACvB,GACD;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC1C;IACE,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf;;;;;;OAMG;IACH,QAAQ,EAAE,OAAO,CAAC;CACnB,CAAC;AAEN,4EAA4E;AAC5E,wBAAgB,sBAAsB,CACpC,EAAE,EAAE,iBAAiB,EACrB,QAAQ,GAAE,MAAM,CAAC,QAA2B,GAC3C,sBAAsB,CA6DxB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@happyvertical/smrt-jobs",
3
- "version": "0.61.3",
3
+ "version": "0.61.4",
4
4
  "smrtJsdoc": "strict",
5
5
  "description": "Background job processing for SMRT objects with persistence and scheduling",
6
6
  "author": "HappyVertical",
@@ -51,18 +51,18 @@
51
51
  }
52
52
  },
53
53
  "dependencies": {
54
- "@happyvertical/jobs": "^0.112.3",
55
- "@happyvertical/logger": "^0.112.3",
56
- "@happyvertical/smrt-config": "0.61.3",
57
- "@happyvertical/smrt-core": "0.61.3",
58
- "@happyvertical/smrt-tenancy": "0.61.3",
59
- "@happyvertical/smrt-types": "0.61.3",
60
- "@happyvertical/smrt-ui": "0.61.3",
61
- "@happyvertical/sql": "^0.112.3",
62
- "@happyvertical/utils": "^0.112.3"
54
+ "@happyvertical/jobs": "^0.113.0",
55
+ "@happyvertical/logger": "^0.113.0",
56
+ "@happyvertical/smrt-config": "0.61.4",
57
+ "@happyvertical/smrt-core": "0.61.4",
58
+ "@happyvertical/smrt-tenancy": "0.61.4",
59
+ "@happyvertical/smrt-types": "0.61.4",
60
+ "@happyvertical/smrt-ui": "0.61.4",
61
+ "@happyvertical/sql": "^0.113.0",
62
+ "@happyvertical/utils": "^0.113.0"
63
63
  },
64
64
  "devDependencies": {
65
- "@happyvertical/smrt-vitest": "0.61.3",
65
+ "@happyvertical/smrt-vitest": "0.61.4",
66
66
  "@sveltejs/package": "^2.5.8",
67
67
  "@sveltejs/vite-plugin-svelte": "^7.3.0",
68
68
  "@types/node": "24.13.6",