@ddd-ts-kit/scheduling 0.9.0 → 0.11.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.
Files changed (145) hide show
  1. package/README.md +73 -7
  2. package/dist/index.d.ts +25 -1
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +13 -1
  5. package/dist/index.js.map +1 -1
  6. package/dist/job-runner.d.ts.map +1 -1
  7. package/dist/job-runner.js +1 -13
  8. package/dist/job-runner.js.map +1 -1
  9. package/dist/metric-names.d.ts +2 -0
  10. package/dist/metric-names.d.ts.map +1 -1
  11. package/dist/metric-names.js +2 -0
  12. package/dist/metric-names.js.map +1 -1
  13. package/dist/process/no-timeout-job-error.d.ts +6 -0
  14. package/dist/process/no-timeout-job-error.d.ts.map +1 -0
  15. package/dist/process/no-timeout-job-error.js +9 -0
  16. package/dist/process/no-timeout-job-error.js.map +1 -0
  17. package/dist/process/stored-process-runner.d.ts +24 -0
  18. package/dist/process/stored-process-runner.d.ts.map +1 -0
  19. package/dist/process/stored-process-runner.js +89 -0
  20. package/dist/process/stored-process-runner.js.map +1 -0
  21. package/dist/queue/background-job-definition.d.ts +9 -0
  22. package/dist/queue/background-job-definition.d.ts.map +1 -0
  23. package/dist/queue/background-job-definition.js +2 -0
  24. package/dist/queue/background-job-definition.js.map +1 -0
  25. package/dist/queue/background-job-observer.d.ts +4 -0
  26. package/dist/queue/background-job-observer.d.ts.map +1 -0
  27. package/dist/queue/background-job-observer.js +2 -0
  28. package/dist/queue/background-job-observer.js.map +1 -0
  29. package/dist/queue/background-job-outcome.d.ts +9 -0
  30. package/dist/queue/background-job-outcome.d.ts.map +1 -0
  31. package/dist/queue/background-job-outcome.js +2 -0
  32. package/dist/queue/background-job-outcome.js.map +1 -0
  33. package/dist/queue/background-job-recorder.d.ts +19 -0
  34. package/dist/queue/background-job-recorder.d.ts.map +1 -0
  35. package/dist/queue/background-job-recorder.js +87 -0
  36. package/dist/queue/background-job-recorder.js.map +1 -0
  37. package/dist/queue/background-job-run.d.ts +15 -0
  38. package/dist/queue/background-job-run.d.ts.map +1 -0
  39. package/dist/queue/background-job-run.js +2 -0
  40. package/dist/queue/background-job-run.js.map +1 -0
  41. package/dist/queue/claimed-job-runner.d.ts +44 -0
  42. package/dist/queue/claimed-job-runner.d.ts.map +1 -0
  43. package/dist/queue/claimed-job-runner.js +178 -0
  44. package/dist/queue/claimed-job-runner.js.map +1 -0
  45. package/dist/queue/errors/attempts-exhausted-error.d.ts +6 -0
  46. package/dist/queue/errors/attempts-exhausted-error.d.ts.map +1 -0
  47. package/dist/queue/errors/attempts-exhausted-error.js +9 -0
  48. package/dist/queue/errors/attempts-exhausted-error.js.map +1 -0
  49. package/dist/queue/errors/invalid-enqueue-error.d.ts +8 -0
  50. package/dist/queue/errors/invalid-enqueue-error.d.ts.map +1 -0
  51. package/dist/queue/errors/invalid-enqueue-error.js +15 -0
  52. package/dist/queue/errors/invalid-enqueue-error.js.map +1 -0
  53. package/dist/queue/errors/job-interrupted-error.d.ts +6 -0
  54. package/dist/queue/errors/job-interrupted-error.d.ts.map +1 -0
  55. package/dist/queue/errors/job-interrupted-error.js +9 -0
  56. package/dist/queue/errors/job-interrupted-error.js.map +1 -0
  57. package/dist/queue/errors/unknown-background-job-error.d.ts +6 -0
  58. package/dist/queue/errors/unknown-background-job-error.d.ts.map +1 -0
  59. package/dist/queue/errors/unknown-background-job-error.js +9 -0
  60. package/dist/queue/errors/unknown-background-job-error.js.map +1 -0
  61. package/dist/queue/queue-state.d.ts +12 -0
  62. package/dist/queue/queue-state.d.ts.map +1 -0
  63. package/dist/queue/queue-state.js +2 -0
  64. package/dist/queue/queue-state.js.map +1 -0
  65. package/dist/queue/queue-worker-options.d.ts +29 -0
  66. package/dist/queue/queue-worker-options.d.ts.map +1 -0
  67. package/dist/queue/queue-worker-options.js +2 -0
  68. package/dist/queue/queue-worker-options.js.map +1 -0
  69. package/dist/queue/queue-worker.d.ts +52 -0
  70. package/dist/queue/queue-worker.d.ts.map +1 -0
  71. package/dist/queue/queue-worker.js +194 -0
  72. package/dist/queue/queue-worker.js.map +1 -0
  73. package/dist/queue/registered-background-job.d.ts +11 -0
  74. package/dist/queue/registered-background-job.d.ts.map +1 -0
  75. package/dist/queue/registered-background-job.js +17 -0
  76. package/dist/queue/registered-background-job.js.map +1 -0
  77. package/dist/queue/report-failed-background-jobs.d.ts +11 -0
  78. package/dist/queue/report-failed-background-jobs.d.ts.map +1 -0
  79. package/dist/queue/report-failed-background-jobs.js +22 -0
  80. package/dist/queue/report-failed-background-jobs.js.map +1 -0
  81. package/dist/queue/running-job.d.ts +14 -0
  82. package/dist/queue/running-job.d.ts.map +1 -0
  83. package/dist/queue/running-job.js +2 -0
  84. package/dist/queue/running-job.js.map +1 -0
  85. package/dist/queue/store/claim-request.d.ts +8 -0
  86. package/dist/queue/store/claim-request.d.ts.map +1 -0
  87. package/dist/queue/store/claim-request.js +2 -0
  88. package/dist/queue/store/claim-request.js.map +1 -0
  89. package/dist/queue/store/claimed-job.d.ts +15 -0
  90. package/dist/queue/store/claimed-job.d.ts.map +1 -0
  91. package/dist/queue/store/claimed-job.js +2 -0
  92. package/dist/queue/store/claimed-job.js.map +1 -0
  93. package/dist/queue/store/in-memory-job-store.d.ts +40 -0
  94. package/dist/queue/store/in-memory-job-store.d.ts.map +1 -0
  95. package/dist/queue/store/in-memory-job-store.js +185 -0
  96. package/dist/queue/store/in-memory-job-store.js.map +1 -0
  97. package/dist/queue/store/job-failure.d.ts +8 -0
  98. package/dist/queue/store/job-failure.d.ts.map +1 -0
  99. package/dist/queue/store/job-failure.js +2 -0
  100. package/dist/queue/store/job-failure.js.map +1 -0
  101. package/dist/queue/store/job-lease.d.ts +9 -0
  102. package/dist/queue/store/job-lease.d.ts.map +1 -0
  103. package/dist/queue/store/job-lease.js +2 -0
  104. package/dist/queue/store/job-lease.js.map +1 -0
  105. package/dist/queue/store/job-store-stats.d.ts +7 -0
  106. package/dist/queue/store/job-store-stats.d.ts.map +1 -0
  107. package/dist/queue/store/job-store-stats.js +2 -0
  108. package/dist/queue/store/job-store-stats.js.map +1 -0
  109. package/dist/queue/store/job-store.d.ts +53 -0
  110. package/dist/queue/store/job-store.d.ts.map +1 -0
  111. package/dist/queue/store/job-store.js +12 -0
  112. package/dist/queue/store/job-store.js.map +1 -0
  113. package/dist/queue/store/job-update.d.ts +7 -0
  114. package/dist/queue/store/job-update.d.ts.map +1 -0
  115. package/dist/queue/store/job-update.js +2 -0
  116. package/dist/queue/store/job-update.js.map +1 -0
  117. package/dist/queue/store/new-job.d.ts +17 -0
  118. package/dist/queue/store/new-job.d.ts.map +1 -0
  119. package/dist/queue/store/new-job.js +2 -0
  120. package/dist/queue/store/new-job.js.map +1 -0
  121. package/dist/queue/store/plain-json.d.ts +3 -0
  122. package/dist/queue/store/plain-json.d.ts.map +1 -0
  123. package/dist/queue/store/plain-json.js +5 -0
  124. package/dist/queue/store/plain-json.js.map +1 -0
  125. package/dist/queue/store/queued-job-of.d.ts +5 -0
  126. package/dist/queue/store/queued-job-of.d.ts.map +1 -0
  127. package/dist/queue/store/queued-job-of.js +18 -0
  128. package/dist/queue/store/queued-job-of.js.map +1 -0
  129. package/dist/queue/store/stored-job.d.ts +22 -0
  130. package/dist/queue/store/stored-job.d.ts.map +1 -0
  131. package/dist/queue/store/stored-job.js +2 -0
  132. package/dist/queue/store/stored-job.js.map +1 -0
  133. package/dist/queue/store/tenant-key-of.d.ts +8 -0
  134. package/dist/queue/store/tenant-key-of.d.ts.map +1 -0
  135. package/dist/queue/store/tenant-key-of.js +9 -0
  136. package/dist/queue/store/tenant-key-of.js.map +1 -0
  137. package/dist/queue/stored-job-queue.d.ts +27 -0
  138. package/dist/queue/stored-job-queue.d.ts.map +1 -0
  139. package/dist/queue/stored-job-queue.js +78 -0
  140. package/dist/queue/stored-job-queue.js.map +1 -0
  141. package/dist/unless-aborted.d.ts +3 -0
  142. package/dist/unless-aborted.d.ts.map +1 -0
  143. package/dist/unless-aborted.js +14 -0
  144. package/dist/unless-aborted.js.map +1 -0
  145. package/package.json +3 -3
@@ -0,0 +1,15 @@
1
+ import type { BackgroundJobOutcome } from './background-job-outcome.js';
2
+ /** One attempt of a background job and what became of it, as data. Never a payload, never a message. */
3
+ export interface BackgroundJobRun {
4
+ readonly job: string;
5
+ readonly jobId: string;
6
+ readonly attempt: number;
7
+ readonly outcome: BackgroundJobOutcome;
8
+ readonly startedAt: Date;
9
+ readonly durationMs: number;
10
+ /** The `code` of what the run threw, or `UNEXPECTED_ERROR`. */
11
+ readonly errorCode?: string;
12
+ /** The correlation of the work that enqueued the job. */
13
+ readonly correlationId: string;
14
+ }
15
+ //# sourceMappingURL=background-job-run.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"background-job-run.d.ts","sourceRoot":"","sources":["../../src/queue/background-job-run.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAExE,wGAAwG;AACxG,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,oBAAoB,CAAC;IACvC,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC;IACzB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,+DAA+D;IAC/D,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,yDAAyD;IACzD,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;CAChC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=background-job-run.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"background-job-run.js","sourceRoot":"","sources":["../../src/queue/background-job-run.ts"],"names":[],"mappings":""}
@@ -0,0 +1,44 @@
1
+ import { type Clock, type ExecutionScope } from '@ddd-ts-kit/kernel';
2
+ import type { JobTimers } from '../job-timers.js';
3
+ import type { BackgroundJobRecorder } from './background-job-recorder.js';
4
+ import type { BackgroundJobRun } from './background-job-run.js';
5
+ import type { RegisteredBackgroundJob } from './registered-background-job.js';
6
+ import type { ClaimedJob } from './store/claimed-job.js';
7
+ import type { JobStore } from './store/job-store.js';
8
+ interface Refusal {
9
+ readonly error: Error;
10
+ /** False when no attempt is left. */
11
+ readonly retry: boolean;
12
+ }
13
+ export interface ClaimedJobRunnerOptions {
14
+ readonly store: JobStore;
15
+ readonly clock: Clock;
16
+ readonly scope: ExecutionScope;
17
+ readonly timers: JobTimers;
18
+ }
19
+ /** Runs one attempt of a claimed job: the execution scope, the heartbeats, the timeout, and what the store is told. */
20
+ export declare class ClaimedJobRunner {
21
+ private readonly options;
22
+ private readonly recorder;
23
+ constructor(options: ClaimedJobRunnerOptions, recorder: BackgroundJobRecorder);
24
+ /** Answers what became of the attempt. Never rejects. `stopping` aborts it when the worker stops. */
25
+ run(job: ClaimedJob, registered: RegisteredBackgroundJob, stopping: AbortSignal): Promise<BackgroundJobRun>;
26
+ /** Settles a job this worker does not run: no attempt is left, or no module registered it. Never rejects. */
27
+ refuse(job: ClaimedJob, registered: RegisteredBackgroundJob, refusal: Refusal): Promise<BackgroundJobRun>;
28
+ private started;
29
+ private attempt;
30
+ private inScope;
31
+ private write;
32
+ private beatLater;
33
+ /** A heartbeat the store cannot take keeps the run going: if the lease ends, the report of the run is refused. */
34
+ private beat;
35
+ private armTimeout;
36
+ private succeeded;
37
+ private failed;
38
+ private settled;
39
+ private retryAt;
40
+ private leaseEnd;
41
+ private recorded;
42
+ }
43
+ export {};
44
+ //# sourceMappingURL=claimed-job-runner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"claimed-job-runner.d.ts","sourceRoot":"","sources":["../../src/queue/claimed-job-runner.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,KAAK,EACV,KAAK,cAAc,E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C,OAAO;YA4BD,KAAK;IAYnB,OAAO,CAAC,SAAS;IAQjB,kHAAkH;YACpG,IAAI;IAUlB,OAAO,CAAC,UAAU;YAYJ,SAAS;YAMT,MAAM;YAcN,OAAO;IAQrB,OAAO,CAAC,OAAO;IAQf,OAAO,CAAC,QAAQ;IAIhB,OAAO,CAAC,QAAQ;CAiBjB"}
@@ -0,0 +1,178 @@
1
+ import { executionContextOfBackgroundJob, retryDelayMs, } from '@ddd-ts-kit/kernel';
2
+ import { errorCodeOf } from '../errors/error-code-of.js';
3
+ import { JobAbortedError } from '../errors/job-aborted-error.js';
4
+ import { JobTimeoutError } from '../errors/job-timeout-error.js';
5
+ import { unlessAborted } from '../unless-aborted.js';
6
+ import { JobInterruptedError } from './errors/job-interrupted-error.js';
7
+ /** Runs one attempt of a claimed job: the execution scope, the heartbeats, the timeout, and what the store is told. */
8
+ export class ClaimedJobRunner {
9
+ options;
10
+ recorder;
11
+ constructor(options, recorder) {
12
+ this.options = options;
13
+ this.recorder = recorder;
14
+ }
15
+ /** Answers what became of the attempt. Never rejects. `stopping` aborts it when the worker stops. */
16
+ async run(job, registered, stopping) {
17
+ const running = this.started(job, registered);
18
+ const unlink = linked(stopping, running.controller, () => new JobAbortedError(job.name));
19
+ const disarm = this.armTimeout(running);
20
+ this.beatLater(running);
21
+ try {
22
+ return await this.attempt(running);
23
+ }
24
+ catch (error) {
25
+ // The store could not be told: the lease ends and the job is claimed again.
26
+ return this.recorded(running, 'interrupted', error);
27
+ }
28
+ finally {
29
+ running.stopBeating();
30
+ disarm();
31
+ unlink();
32
+ }
33
+ }
34
+ /** Settles a job this worker does not run: no attempt is left, or no module registered it. Never rejects. */
35
+ async refuse(job, registered, refusal) {
36
+ const running = this.started(job, registered);
37
+ try {
38
+ return await this.settled(running, refusal.error, refusal.retry ? this.retryAt(running) : null);
39
+ }
40
+ catch (error) {
41
+ return this.recorded(running, 'interrupted', error);
42
+ }
43
+ }
44
+ started(job, registered) {
45
+ return {
46
+ job,
47
+ registered,
48
+ lease: { id: job.id, attempt: job.attempt },
49
+ controller: new AbortController(),
50
+ startedAt: this.options.clock.now(),
51
+ stopBeating: nothing,
52
+ };
53
+ }
54
+ async attempt(running) {
55
+ try {
56
+ await unlessAborted(running.controller.signal, this.inScope(running));
57
+ }
58
+ catch (error) {
59
+ return this.failed(running, error);
60
+ }
61
+ return this.succeeded(running);
62
+ }
63
+ inScope(running) {
64
+ const { job, registered, controller, startedAt } = running;
65
+ const { timeoutMs } = registered.policy;
66
+ const deadline = timeoutMs === undefined ? undefined : new Date(startedAt.getTime() + timeoutMs);
67
+ const { traceparent } = job.enqueuedBy;
68
+ const context = executionContextOfBackgroundJob({
69
+ jobId: job.id,
70
+ enqueuedBy: job.enqueuedBy,
71
+ ...(deadline === undefined ? {} : { deadline }),
72
+ });
73
+ const execution = {
74
+ jobId: job.id,
75
+ attempt: job.attempt,
76
+ enqueuedAt: job.enqueuedAt,
77
+ actor: job.enqueuedBy.actor,
78
+ startedAt,
79
+ checkpoint: job.checkpoint,
80
+ signal: controller.signal,
81
+ ...(traceparent === undefined ? {} : { traceparent }),
82
+ saveCheckpoint: (checkpoint) => this.write(running, { checkpoint }),
83
+ reportProgress: (progress) => this.write(running, { progress }),
84
+ };
85
+ return this.options.scope.run(context, () => registered.definition.run(job.payload, execution));
86
+ }
87
+ async write(running, update) {
88
+ const held = await this.options.store.update(running.lease, update, this.leaseEnd(running));
89
+ if (!held) {
90
+ const interrupted = new JobInterruptedError(running.job.name);
91
+ running.controller.abort(interrupted);
92
+ throw interrupted;
93
+ }
94
+ }
95
+ beatLater(running) {
96
+ const every = Math.max(1, Math.floor(running.registered.policy.leaseMs / 3));
97
+ running.stopBeating = this.options.timers.schedule(every, () => {
98
+ void this.beat(running);
99
+ });
100
+ }
101
+ /** A heartbeat the store cannot take keeps the run going: if the lease ends, the report of the run is refused. */
102
+ async beat(running) {
103
+ const held = await this.options.store.heartbeat(running.lease, this.leaseEnd(running)).catch(() => true);
104
+ if (held) {
105
+ this.beatLater(running);
106
+ }
107
+ else {
108
+ running.controller.abort(new JobInterruptedError(running.job.name));
109
+ }
110
+ }
111
+ armTimeout({ registered, controller, job }) {
112
+ const { timeoutMs } = registered.policy;
113
+ if (timeoutMs === undefined) {
114
+ return nothing;
115
+ }
116
+ return this.options.timers.schedule(timeoutMs, () => {
117
+ controller.abort(new JobTimeoutError(job.name, timeoutMs));
118
+ });
119
+ }
120
+ async succeeded(running) {
121
+ const held = await this.options.store.complete(running.lease, this.options.clock.now());
122
+ return this.recorded(running, held ? 'succeeded' : 'interrupted');
123
+ }
124
+ async failed(running, error) {
125
+ if (error instanceof JobInterruptedError) {
126
+ return this.recorded(running, 'interrupted', error);
127
+ }
128
+ if (error instanceof JobAbortedError) {
129
+ const released = await this.options.store.release(running.lease, this.options.clock.now());
130
+ return this.recorded(running, released ? 'released' : 'interrupted', error);
131
+ }
132
+ return this.settled(running, error, this.retryAt(running));
133
+ }
134
+ async settled(running, error, retryAt) {
135
+ const failure = { errorCode: errorCodeOf(error), retryAt, at: this.options.clock.now() };
136
+ const held = await this.options.store.fail(running.lease, failure);
137
+ const outcome = !held ? 'interrupted' : retryAt === null ? 'dead' : 'retried';
138
+ return this.recorded(running, outcome, error);
139
+ }
140
+ retryAt({ job, registered }) {
141
+ if (job.attempt >= registered.policy.maxAttempts) {
142
+ return null;
143
+ }
144
+ return new Date(this.options.clock.now().getTime() + retryDelayMs(registered.policy, job.attempt));
145
+ }
146
+ leaseEnd(running) {
147
+ return new Date(this.options.clock.now().getTime() + running.registered.policy.leaseMs);
148
+ }
149
+ recorded(running, outcome, error) {
150
+ const { job, startedAt } = running;
151
+ const durationMs = this.options.clock.now().getTime() - startedAt.getTime();
152
+ const run = {
153
+ job: job.name,
154
+ jobId: job.id,
155
+ attempt: job.attempt,
156
+ outcome,
157
+ startedAt,
158
+ durationMs,
159
+ correlationId: job.enqueuedBy.correlationId,
160
+ ...(error === undefined ? {} : { errorCode: errorCodeOf(error) }),
161
+ };
162
+ return this.recorder.record(run, error);
163
+ }
164
+ }
165
+ function nothing() {
166
+ return undefined;
167
+ }
168
+ /** Aborts `controller` when `signal` is, with the reason `reason` gives. Answers how to stop listening. */
169
+ function linked(signal, controller, reason) {
170
+ const abort = () => {
171
+ controller.abort(reason());
172
+ };
173
+ signal.addEventListener('abort', abort, { once: true });
174
+ return () => {
175
+ signal.removeEventListener('abort', abort);
176
+ };
177
+ }
178
+ //# sourceMappingURL=claimed-job-runner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"claimed-job-runner.js","sourceRoot":"","sources":["../../src/queue/claimed-job-runner.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,+BAA+B,EAC/B,YAAY,GAKb,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAEjE,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAIrD,OAAO,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AAoBxE,uHAAuH;AACvH,MAAM,OAAO,gBAAgB;IAER,OAAO;IACP,QAAQ;IAF3B,YACmB,OAAgC,EAChC,QAA+B;uBAD/B,OAAO;wBACP,QAAQ;IACxB,CAAC;IAEJ,qGAAqG;IACrG,KAAK,CAAC,GAAG,CAAC,GAAe,EAAE,UAAmC,EAAE,QAAqB;QACnF,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;QAC9C,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,UAAU,EAAE,GAAG,EAAE,CAAC,IAAI,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;QACzF,MAAM,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QAEx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,CAAC;QAEF,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAC1C,CAAC;CACF;AAED,SAAS,OAAO;IACd,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,2GAA2G;AAC3G,SAAS,MAAM,CAAC,MAAmB,EAAE,UAA2B,EAAE,MAAmB;IACnF,MAAM,KAAK,GAAG,GAAG,EAAE;QACjB,UAAU,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;IAC7B,CAAC,CAAC;IAEF,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;IAExD,OAAO,GAAG,EAAE;QACV,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IAC7C,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,6 @@
1
+ /** A job claimed again after its last attempt: its worker died, or lost its lease, during that attempt. */
2
+ export declare class AttemptsExhaustedError extends Error {
3
+ readonly code = "ATTEMPTS_EXHAUSTED";
4
+ constructor(job: string, maxAttempts: number);
5
+ }
6
+ //# sourceMappingURL=attempts-exhausted-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attempts-exhausted-error.d.ts","sourceRoot":"","sources":["../../../src/queue/errors/attempts-exhausted-error.ts"],"names":[],"mappings":"AAAA,2GAA2G;AAC3G,qBAAa,sBAAuB,SAAQ,KAAK;IAC/C,QAAQ,CAAC,IAAI,wBAAwB;IAErC,YAAY,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAG3C;CACF"}
@@ -0,0 +1,9 @@
1
+ /** A job claimed again after its last attempt: its worker died, or lost its lease, during that attempt. */
2
+ export class AttemptsExhaustedError extends Error {
3
+ code = 'ATTEMPTS_EXHAUSTED';
4
+ constructor(job, maxAttempts) {
5
+ super(`Background job "${job}" used its ${maxAttempts} attempt(s).`);
6
+ this.name = 'AttemptsExhaustedError';
7
+ }
8
+ }
9
+ //# sourceMappingURL=attempts-exhausted-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attempts-exhausted-error.js","sourceRoot":"","sources":["../../../src/queue/errors/attempts-exhausted-error.ts"],"names":[],"mappings":"AAAA,2GAA2G;AAC3G,MAAM,OAAO,sBAAuB,SAAQ,KAAK;IACtC,IAAI,GAAG,oBAAoB,CAAC;IAErC,YAAY,GAAW,EAAE,WAAmB;QAC1C,KAAK,CAAC,mBAAmB,GAAG,cAAc,WAAW,cAAc,CAAC,CAAC;QACrE,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAC;IACvC,CAAC;CACF"}
@@ -0,0 +1,8 @@
1
+ /** What `enqueue` cannot accept: raised where the job is enqueued, before anything is stored. */
2
+ export declare class InvalidEnqueueError extends Error {
3
+ readonly code = "INVALID_ENQUEUE";
4
+ private constructor();
5
+ static unnamed(jobName: string): InvalidEnqueueError;
6
+ static twoInstants(): InvalidEnqueueError;
7
+ }
8
+ //# sourceMappingURL=invalid-enqueue-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invalid-enqueue-error.d.ts","sourceRoot":"","sources":["../../../src/queue/errors/invalid-enqueue-error.ts"],"names":[],"mappings":"AAAA,iGAAiG;AACjG,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C,QAAQ,CAAC,IAAI,qBAAqB;IAElC,OAAO,eAGN;IAED,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,mBAAmB,CAInD;IAED,MAAM,CAAC,WAAW,IAAI,mBAAmB,CAExC;CACF"}
@@ -0,0 +1,15 @@
1
+ /** What `enqueue` cannot accept: raised where the job is enqueued, before anything is stored. */
2
+ export class InvalidEnqueueError extends Error {
3
+ code = 'INVALID_ENQUEUE';
4
+ constructor(message) {
5
+ super(message);
6
+ this.name = 'InvalidEnqueueError';
7
+ }
8
+ static unnamed(jobName) {
9
+ return new InvalidEnqueueError(`"${jobName}" is not a job name: the static jobName of a background job is <context>.<job-name>.`);
10
+ }
11
+ static twoInstants() {
12
+ return new InvalidEnqueueError('A job is enqueued with a delay or a runAt, not both.');
13
+ }
14
+ }
15
+ //# sourceMappingURL=invalid-enqueue-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invalid-enqueue-error.js","sourceRoot":"","sources":["../../../src/queue/errors/invalid-enqueue-error.ts"],"names":[],"mappings":"AAAA,iGAAiG;AACjG,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IACnC,IAAI,GAAG,iBAAiB,CAAC;IAElC,YAAoB,OAAe;QACjC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACpC,CAAC;IAED,MAAM,CAAC,OAAO,CAAC,OAAe;QAC5B,OAAO,IAAI,mBAAmB,CAC5B,IAAI,OAAO,sFAAsF,CAClG,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,WAAW;QAChB,OAAO,IAAI,mBAAmB,CAAC,sDAAsD,CAAC,CAAC;IACzF,CAAC;CACF"}
@@ -0,0 +1,6 @@
1
+ /** The store no longer gives this run the job: it was cancelled, or its lease expired and another worker claimed it. */
2
+ export declare class JobInterruptedError extends Error {
3
+ readonly code = "JOB_INTERRUPTED";
4
+ constructor(job: string);
5
+ }
6
+ //# sourceMappingURL=job-interrupted-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"job-interrupted-error.d.ts","sourceRoot":"","sources":["../../../src/queue/errors/job-interrupted-error.ts"],"names":[],"mappings":"AAAA,wHAAwH;AACxH,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C,QAAQ,CAAC,IAAI,qBAAqB;IAElC,YAAY,GAAG,EAAE,MAAM,EAGtB;CACF"}
@@ -0,0 +1,9 @@
1
+ /** The store no longer gives this run the job: it was cancelled, or its lease expired and another worker claimed it. */
2
+ export class JobInterruptedError extends Error {
3
+ code = 'JOB_INTERRUPTED';
4
+ constructor(job) {
5
+ super(`Background job "${job}" was cancelled or claimed by another worker: this run stops.`);
6
+ this.name = 'JobInterruptedError';
7
+ }
8
+ }
9
+ //# sourceMappingURL=job-interrupted-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"job-interrupted-error.js","sourceRoot":"","sources":["../../../src/queue/errors/job-interrupted-error.ts"],"names":[],"mappings":"AAAA,wHAAwH;AACxH,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IACnC,IAAI,GAAG,iBAAiB,CAAC;IAElC,YAAY,GAAW;QACrB,KAAK,CAAC,mBAAmB,GAAG,+DAA+D,CAAC,CAAC;QAC7F,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACpC,CAAC;CACF"}
@@ -0,0 +1,6 @@
1
+ /** A worker claimed a job of its queue that no module registered: a newer version enqueued it, or it was renamed. */
2
+ export declare class UnknownBackgroundJobError extends Error {
3
+ readonly code = "UNKNOWN_BACKGROUND_JOB";
4
+ constructor(job: string);
5
+ }
6
+ //# sourceMappingURL=unknown-background-job-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unknown-background-job-error.d.ts","sourceRoot":"","sources":["../../../src/queue/errors/unknown-background-job-error.ts"],"names":[],"mappings":"AAAA,qHAAqH;AACrH,qBAAa,yBAA0B,SAAQ,KAAK;IAClD,QAAQ,CAAC,IAAI,4BAA4B;IAEzC,YAAY,GAAG,EAAE,MAAM,EAGtB;CACF"}
@@ -0,0 +1,9 @@
1
+ /** A worker claimed a job of its queue that no module registered: a newer version enqueued it, or it was renamed. */
2
+ export class UnknownBackgroundJobError extends Error {
3
+ code = 'UNKNOWN_BACKGROUND_JOB';
4
+ constructor(job) {
5
+ super(`No background job is named "${job}" in this worker.`);
6
+ this.name = 'UnknownBackgroundJobError';
7
+ }
8
+ }
9
+ //# sourceMappingURL=unknown-background-job-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unknown-background-job-error.js","sourceRoot":"","sources":["../../../src/queue/errors/unknown-background-job-error.ts"],"names":[],"mappings":"AAAA,qHAAqH;AACrH,MAAM,OAAO,yBAA0B,SAAQ,KAAK;IACzC,IAAI,GAAG,wBAAwB,CAAC;IAEzC,YAAY,GAAW;QACrB,KAAK,CAAC,+BAA+B,GAAG,mBAAmB,CAAC,CAAC;QAC7D,IAAI,CAAC,IAAI,GAAG,2BAA2B,CAAC;IAC1C,CAAC;CACF"}
@@ -0,0 +1,12 @@
1
+ import type { BackgroundJobRun } from './background-job-run.js';
2
+ /** What a worker follows of one queue. */
3
+ export interface QueueState {
4
+ readonly name: string;
5
+ readonly concurrency: number;
6
+ /** The attempts in progress. */
7
+ readonly active: Set<Promise<BackgroundJobRun>>;
8
+ /** The claim in progress and the launch of what it claimed, which `stop` waits for. */
9
+ filling: Promise<void> | undefined;
10
+ cancelSleep: (() => void) | undefined;
11
+ }
12
+ //# sourceMappingURL=queue-state.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queue-state.d.ts","sourceRoot":"","sources":["../../src/queue/queue-state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAEhE,0CAA0C;AAC1C,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,gCAAgC;IAChC,QAAQ,CAAC,MAAM,EAAE,GAAG,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC;IAChD,uFAAuF;IACvF,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC;IACnC,WAAW,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,SAAS,CAAC;CACvC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=queue-state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queue-state.js","sourceRoot":"","sources":["../../src/queue/queue-state.ts"],"names":[],"mappings":""}
@@ -0,0 +1,29 @@
1
+ import type { Clock, ExecutionScope, Logger, Metrics } from '@ddd-ts-kit/kernel';
2
+ import type { JobTimers } from '../job-timers.js';
3
+ import type { BackgroundJobObserver } from './background-job-observer.js';
4
+ import type { JobStore } from './store/job-store.js';
5
+ export interface QueueWorkerOptions {
6
+ readonly store: JobStore;
7
+ /** Every instant comes from it. */
8
+ readonly clock: Clock;
9
+ /** Each attempt runs inside it, in a context of origin `queue`. */
10
+ readonly scope: ExecutionScope;
11
+ /** Default: writes nothing. */
12
+ readonly logger?: Logger;
13
+ /** Default: measures nothing. */
14
+ readonly metrics?: Metrics;
15
+ /** Default: the timers of the runtime. */
16
+ readonly timers?: JobTimers;
17
+ /**
18
+ * How many attempts of one queue run at once in this process: a number for every queue, or a
19
+ * number per queue with `default` for the others. Default 1. A limit per process, not across
20
+ * the workers of a deployment.
21
+ */
22
+ readonly concurrency?: number | Readonly<Record<string, number>>;
23
+ /** How long an idle queue waits before it asks the store again. Default 1000. */
24
+ readonly pollIntervalMs?: number;
25
+ /** How long `stop()` waits for the attempts in progress before aborting them. Default 30 000. */
26
+ readonly graceMs?: number;
27
+ readonly onRun?: BackgroundJobObserver;
28
+ }
29
+ //# sourceMappingURL=queue-worker-options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queue-worker-options.d.ts","sourceRoot":"","sources":["../../src/queue/queue-worker-options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AACjF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAErD,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC;IACzB,mCAAmC;IACnC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;IACtB,mEAAmE;IACnE,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAC;IAC/B,+BAA+B;IAC/B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,iCAAiC;IACjC,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAC3B,0CAA0C;IAC1C,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,CAAC;IAC5B;;;;OAIG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACjE,iFAAiF;IACjF,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IACjC,iGAAiG;IACjG,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,KAAK,CAAC,EAAE,qBAAqB,CAAC;CACxC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=queue-worker-options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queue-worker-options.js","sourceRoot":"","sources":["../../src/queue/queue-worker-options.ts"],"names":[],"mappings":""}
@@ -0,0 +1,52 @@
1
+ import type { BackgroundJobDefinition } from './background-job-definition.js';
2
+ import type { BackgroundJobRun } from './background-job-run.js';
3
+ import type { QueueWorkerOptions } from './queue-worker-options.js';
4
+ /**
5
+ * Runs the background jobs of the queues it has jobs for, in this process: each queue is the
6
+ * context of its jobs, so a worker given the modules of some contexts consumes their queues and
7
+ * no other. Delivery is at least once: a job whose worker died comes back when its lease ends.
8
+ */
9
+ export declare class QueueWorker {
10
+ private readonly options;
11
+ private readonly jobs;
12
+ private readonly queues;
13
+ private readonly recorder;
14
+ private readonly runner;
15
+ private stopping;
16
+ private running;
17
+ constructor(options: QueueWorkerOptions);
18
+ /** Throws `DuplicateJobError` for a name already registered, `InvalidJobScheduleError` for options it cannot read. */
19
+ register(definition: BackgroundJobDefinition): void;
20
+ /** The names of the queues this worker consumes. */
21
+ queueNames(): readonly string[];
22
+ /** Starts claiming. Starting twice does nothing. */
23
+ start(): Promise<void>;
24
+ /**
25
+ * Stops claiming, waits for the attempts in progress up to the grace period, then aborts them:
26
+ * an aborted attempt gives its job back, uncounted, for the next worker. A claim in flight
27
+ * when it is called gives its jobs back the same way. Stopping is cooperative: a job that
28
+ * ignores its signal goes on behind, and is claimed again once its lease ends.
29
+ */
30
+ stop(): Promise<void>;
31
+ /**
32
+ * Claims and runs every job due now, queue after queue, until none is left, and answers the
33
+ * attempts: for a test, or a command run once. Not while the worker runs.
34
+ */
35
+ runDue(): Promise<BackgroundJobRun[]>;
36
+ private followed;
37
+ private concurrencyOf;
38
+ /** Claims while there is room and work; an idle queue sleeps, a full one waits for an attempt to end. */
39
+ private pump;
40
+ /** Never rejects: a fault of the store is recorded, and the queue asks again after a poll. */
41
+ private fillOrSleep;
42
+ private fill;
43
+ private claimed;
44
+ /** Read anew after an await: `stop()` may have been called while it waited. */
45
+ private stopped;
46
+ /** Jobs claimed while the worker stopped go back to the store, their attempt not counted. */
47
+ private giveBack;
48
+ private launch;
49
+ private attempt;
50
+ private sleep;
51
+ }
52
+ //# sourceMappingURL=queue-worker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queue-worker.d.ts","sourceRoot":"","sources":["../../src/queue/queue-worker.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAE9E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAKhE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAIpE;;;;GAIG;AACH,qBAAa,WAAW;IAaV,OAAO,CAAC,QAAQ,CAAC,OAAO;IAZpC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAA8C;IAEnE,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAiC;IAExD,OAAO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