@workflow/world-postgres 5.1.1 → 5.2.0

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,23 +1,54 @@
1
1
  import type { Pool } from 'pg';
2
2
  /**
3
- * Seconds a claimed Graphile job's lock may go unrenewed before another
4
- * process releases it for redelivery. Off (`0`) by default: during a rolling
5
- * upgrade, a process on an earlier version neither renews its locks nor fences
6
- * its acknowledgement, so if an upgraded process released one of its long
7
- * deliveries, the old holder's unfenced `completeJob` could delete the
8
- * successor's row when it finished. Deployments with more than one process
9
- * should turn it on (30 seconds is a good value) once every process runs a
10
- * version that renews.
3
+ * The stale window when neither `jobLockStaleSeconds` nor
4
+ * `WORKFLOW_POSTGRES_JOB_LOCK_STALE_SECONDS` is set: every delivery renews its
5
+ * lock, and the release of stale locks covers only the per-run named queues
6
+ * (a spec 9 run's orchestrator deliveries, invoke mode's executor lane) and
7
+ * only jobs whose holder registered itself as renewing (see
8
+ * {@link JobLeasePolicy}). Well above an inline step's longest synchronous
9
+ * stretch, so a blocked event loop does not turn into a second owner of a
10
+ * running inline step, and far below Graphile Worker's fixed 4 hours.
11
11
  */
12
- export declare const DEFAULT_JOB_LOCK_STALE_SECONDS = 0;
12
+ export declare const DEFAULT_NAMED_QUEUE_LOCK_STALE_SECONDS = 300;
13
13
  export declare const JOB_LOCK_STALE_SECONDS_ENV = "WORKFLOW_POSTGRES_JOB_LOCK_STALE_SECONDS";
14
14
  /**
15
- * Resolve the stale window: the `jobLockStaleSeconds` option, then
16
- * `WORKFLOW_POSTGRES_JOB_LOCK_STALE_SECONDS`, then the default. `0` turns
17
- * renewal and the stale-lock sweep off, which leaves recovery to Graphile
18
- * Worker's fixed 4 hour reset and to `reenqueueActiveRuns` on start.
15
+ * What this process renews and releases.
16
+ *
17
+ * - `'all'`: `jobLockStaleSeconds` (or the environment variable) set above
18
+ * `0`. Releases every job of this World's tasks whose lock went unrenewed
19
+ * for the window, whoever holds it. The operator asserts that every process
20
+ * sharing the database renews.
21
+ * - `'named-queues'`: the default. Releases only jobs in this World's per-run
22
+ * named queues, and only those whose holder is a worker registered in
23
+ * `workflow.workflow_job_lock_holders`, which only a renewing process
24
+ * writes. A process on an earlier version (5.1.0 renews only when the
25
+ * window is set) never registers, so its long deliveries are never released
26
+ * under it and its unfenced acknowledgement cannot delete a redelivery's
27
+ * row. Its jobs keep Graphile Worker's 4 hour reset.
28
+ * - `'off'`: `0` set explicitly. Neither renews nor releases.
29
+ */
30
+ export type JobLeasePolicy = {
31
+ scope: 'off';
32
+ staleSeconds: 0;
33
+ } | {
34
+ scope: 'all' | 'named-queues';
35
+ staleSeconds: number;
36
+ };
37
+ /**
38
+ * Resolve the explicitly configured stale window: the `jobLockStaleSeconds`
39
+ * option, then `WORKFLOW_POSTGRES_JOB_LOCK_STALE_SECONDS`. `undefined` when
40
+ * neither is set (or the environment value is invalid), which selects the
41
+ * default policy (see {@link resolveJobLeasePolicy}).
19
42
  */
20
- export declare function resolveJobLockStaleSeconds(configured?: number): number;
43
+ export declare function resolveJobLockStaleSeconds(configured?: number): number | undefined;
44
+ /**
45
+ * The lease policy: an explicit window above `0` releases every job of this
46
+ * World (`'all'`), an explicit `0` turns renewal and release off, and no
47
+ * setting renews every delivery and releases only per-run named-queue jobs of
48
+ * registered (renewing) holders after
49
+ * {@link DEFAULT_NAMED_QUEUE_LOCK_STALE_SECONDS} (`'named-queues'`).
50
+ */
51
+ export declare function resolveJobLeasePolicy(configured?: number, defaultStaleSeconds?: number): JobLeasePolicy;
21
52
  /**
22
53
  * Thrown in place of a delivery's result when this process can no longer show
23
54
  * that it holds the delivery's job lock. Graphile Worker completes a job with a
@@ -37,13 +68,26 @@ export interface JobLeases {
37
68
  readonly enabled: boolean;
38
69
  /** Renew a task's job lock while it runs, and refuse to acknowledge a delivery whose lock was lost. */
39
70
  wrap(task: GraphileTask): GraphileTask;
40
- /** Start releasing this World's jobs whose locks went unrenewed. Idempotent. */
41
- startSweeper(taskIdentifiers: string[]): void;
71
+ /**
72
+ * Start releasing this World's jobs whose locks went unrenewed. Idempotent.
73
+ * Under the `'named-queues'` scope only jobs in a named queue
74
+ * `<namedQueues.prefix><runId><namedQueues.suffix>` are released, and
75
+ * without `namedQueues` nothing is.
76
+ */
77
+ startSweeper(taskIdentifiers: string[], namedQueues?: {
78
+ prefix: string;
79
+ suffix: string;
80
+ }): void;
42
81
  /** Stop renewing and sweeping, and wait for queries in flight. */
43
82
  stop(): Promise<void>;
44
83
  }
45
84
  export interface JobLeaseOptions {
46
85
  staleSeconds: number;
86
+ /**
87
+ * What the sweep releases (see {@link JobLeasePolicy}). Defaults to
88
+ * `'all'`. Renewal and holder registration are the same in both scopes.
89
+ */
90
+ scope?: 'all' | 'named-queues';
47
91
  /** Monotonic clock in milliseconds; injectable for tests. */
48
92
  now?: () => number;
49
93
  random?: () => number;
@@ -58,7 +102,15 @@ export interface JobLeaseOptions {
58
102
  * hosts nothing redelivers it until a process restarts and re-enqueues active
59
103
  * runs. A healthy delivery that runs longer than 4 hours is reset while it
60
104
  * runs and delivered twice.
105
+ *
106
+ * Every renewing worker also registers itself in
107
+ * `workflow.workflow_job_lock_holders` before its delivery runs (once an hour
108
+ * per worker, and again on a renewal tick if that failed). Under the
109
+ * `'named-queues'` scope, the sweep releases only jobs of registered workers,
110
+ * so a process that does not renew (an earlier version) is never released
111
+ * under. A missing table never fails a delivery: the job's own lock renewal
112
+ * and the acknowledgement fence do not read it.
61
113
  */
62
- export declare function createJobLeases(pool: Pool, { staleSeconds, now, random, }: JobLeaseOptions): JobLeases;
114
+ export declare function createJobLeases(pool: Pool, { staleSeconds, scope, now, random, }: JobLeaseOptions): JobLeases;
63
115
  export {};
64
116
  //# sourceMappingURL=job-lease.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"job-lease.d.ts","sourceRoot":"","sources":["../src/job-lease.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;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