@ultimat3/jobs 2.0.0 → 4.0.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.
- package/CLAUDE.md +146 -15
- package/README.md +80 -4
- package/package.json +5 -5
- package/src/backfill-errors.ts +137 -0
- package/src/backfill-gate.ts +5 -5
- package/src/backfill-pass.ts +1 -1
- package/src/describe.ts +17 -1
- package/src/driver-memory.ts +34 -8
- package/src/driver-pg-ddl.ts +31 -6
- package/src/driver-pg-rows.ts +34 -6
- package/src/driver-pg-sql.ts +79 -9
- package/src/driver-pg.ts +15 -5
- package/src/driver.ts +36 -12
- package/src/errors.ts +81 -130
- package/src/execute.ts +33 -9
- package/src/heartbeat.ts +15 -13
- package/src/index.ts +23 -8
- package/src/job.ts +55 -1
- package/src/metrics.ts +1 -1
- package/src/outbox-lease.ts +29 -0
- package/src/outbox-pg.ts +58 -7
- package/src/outbox.ts +91 -8
- package/src/register.ts +25 -1
- package/src/renewal-timer.ts +35 -0
- package/src/retry-classification.ts +112 -0
- package/src/retry.ts +4 -3
- package/src/steps.ts +14 -1
- package/src/task.ts +29 -2
- package/src/worker-fleet-slots.ts +16 -11
- package/src/worker-run.ts +3 -0
- package/src/worker.ts +34 -9
package/src/worker.ts
CHANGED
|
@@ -161,6 +161,26 @@ export function createWorker(options: WorkerOptions): Worker {
|
|
|
161
161
|
...(options.events === undefined ? {} : { events: options.events }),
|
|
162
162
|
});
|
|
163
163
|
|
|
164
|
+
/**
|
|
165
|
+
* A claimed job handed straight back over a cap. It is NOT a suspension and NOT a failure: no
|
|
166
|
+
* `park`, so the row stays where `queue_depth` and `queue_oldest_ready_seconds` can see it, and
|
|
167
|
+
* no `error`, so `x jobs show` does not report a `lastError` for a job that never ran. It was
|
|
168
|
+
* both of those until 2026-08 — parked beside a 3-day `step.sleep`, and stamped with a failure
|
|
169
|
+
* it never had — which is why the two sheds go through one function now.
|
|
170
|
+
*/
|
|
171
|
+
const shed = async (
|
|
172
|
+
claimed: ClaimedJob,
|
|
173
|
+
detail: { readonly queue: string; readonly reason: string },
|
|
174
|
+
): Promise<void> => {
|
|
175
|
+
logger.debug('jobs.worker.shed', {
|
|
176
|
+
workerId,
|
|
177
|
+
job: claimed.name,
|
|
178
|
+
jobId: claimed.id,
|
|
179
|
+
...detail,
|
|
180
|
+
});
|
|
181
|
+
await options.driver.nack(claimed.id, { delayMs: pollIntervalMs, countsAsAttempt: false });
|
|
182
|
+
};
|
|
183
|
+
|
|
164
184
|
/** The drain's one question: may this worker still take work off the queue? */
|
|
165
185
|
const claiming = (): boolean => state !== 'draining' && state !== 'stopped';
|
|
166
186
|
|
|
@@ -196,11 +216,17 @@ export function createWorker(options: WorkerOptions): Worker {
|
|
|
196
216
|
...(job.tenantId === undefined ? {} : { tenantId: job.tenantId }),
|
|
197
217
|
});
|
|
198
218
|
if (lease === undefined) {
|
|
199
|
-
// Over a tenant/queue/global cap: hand it straight back for another worker.
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
219
|
+
// Over a tenant/queue/global cap: hand it straight back for another worker. No `park`
|
|
220
|
+
// and no `error` — the row stays in the ready bucket the depth gauge reads, and nothing
|
|
221
|
+
// about this job failed, so `x jobs show` must not report a `lastError` for it. The
|
|
222
|
+
// reason is a log FIELD instead, where it costs nothing when nobody is asking.
|
|
223
|
+
await shed(job, {
|
|
224
|
+
queue,
|
|
225
|
+
reason:
|
|
226
|
+
limiter.blockedBy({
|
|
227
|
+
queue,
|
|
228
|
+
...(job.tenantId === undefined ? {} : { tenantId: job.tenantId }),
|
|
229
|
+
}) ?? 'unknown',
|
|
204
230
|
});
|
|
205
231
|
continue;
|
|
206
232
|
}
|
|
@@ -223,10 +249,9 @@ export function createWorker(options: WorkerOptions): Worker {
|
|
|
223
249
|
}
|
|
224
250
|
if (!granted) {
|
|
225
251
|
lease.release();
|
|
226
|
-
await
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
error: `limited: job concurrency (${getJob(job.name)?.concurrency ?? 0})`,
|
|
252
|
+
await shed(job, {
|
|
253
|
+
queue,
|
|
254
|
+
reason: `job concurrency (${getJob(job.name)?.concurrency ?? 0})`,
|
|
230
255
|
});
|
|
231
256
|
continue;
|
|
232
257
|
}
|