@ultimat3/jobs 1.0.0 → 1.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.
- package/package.json +5 -5
- package/src/worker.ts +33 -1
- package/src/clock.d.ts +0 -7
- package/src/clock.d.ts.map +0 -1
- package/src/clock.js +0 -21
- package/src/clock.js.map +0 -1
- package/src/driver-memory.d.ts +0 -9
- package/src/driver-memory.d.ts.map +0 -1
- package/src/driver-memory.js +0 -189
- package/src/driver-memory.js.map +0 -1
- package/src/driver-nats.d.ts +0 -7
- package/src/driver-nats.d.ts.map +0 -1
- package/src/driver-nats.js +0 -51
- package/src/driver-nats.js.map +0 -1
- package/src/driver-pg-sql.d.ts +0 -19
- package/src/driver-pg-sql.d.ts.map +0 -1
- package/src/driver-pg-sql.js +0 -160
- package/src/driver-pg-sql.js.map +0 -1
- package/src/driver-pg.d.ts +0 -17
- package/src/driver-pg.d.ts.map +0 -1
- package/src/driver-pg.js +0 -246
- package/src/driver-pg.js.map +0 -1
- package/src/driver-redis.d.ts +0 -7
- package/src/driver-redis.d.ts.map +0 -1
- package/src/driver-redis.js +0 -54
- package/src/driver-redis.js.map +0 -1
- package/src/driver.d.ts +0 -114
- package/src/driver.d.ts.map +0 -1
- package/src/driver.js +0 -14
- package/src/driver.js.map +0 -1
- package/src/errors.d.ts +0 -63
- package/src/errors.d.ts.map +0 -1
- package/src/errors.js +0 -105
- package/src/errors.js.map +0 -1
- package/src/events.d.ts +0 -35
- package/src/events.d.ts.map +0 -1
- package/src/events.js +0 -92
- package/src/events.js.map +0 -1
- package/src/index.d.ts +0 -32
- package/src/index.d.ts.map +0 -1
- package/src/index.js +0 -18
- package/src/index.js.map +0 -1
- package/src/inspect.d.ts +0 -82
- package/src/inspect.d.ts.map +0 -1
- package/src/inspect.js +0 -113
- package/src/inspect.js.map +0 -1
- package/src/job.d.ts +0 -71
- package/src/job.d.ts.map +0 -1
- package/src/job.js +0 -99
- package/src/job.js.map +0 -1
- package/src/limits.d.ts +0 -47
- package/src/limits.d.ts.map +0 -1
- package/src/limits.js +0 -0
- package/src/limits.js.map +0 -1
- package/src/outbox.d.ts +0 -81
- package/src/outbox.d.ts.map +0 -1
- package/src/outbox.js +0 -202
- package/src/outbox.js.map +0 -1
- package/src/retry.d.ts +0 -40
- package/src/retry.d.ts.map +0 -1
- package/src/retry.js +0 -59
- package/src/retry.js.map +0 -1
- package/src/scheduler.d.ts +0 -79
- package/src/scheduler.d.ts.map +0 -1
- package/src/scheduler.js +0 -183
- package/src/scheduler.js.map +0 -1
- package/src/steps.d.ts +0 -86
- package/src/steps.d.ts.map +0 -1
- package/src/steps.js +0 -227
- package/src/steps.js.map +0 -1
- package/src/worker.d.ts +0 -68
- package/src/worker.d.ts.map +0 -1
- package/src/worker.js +0 -273
- package/src/worker.js.map +0 -1
package/src/events.d.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import type { Clock } from '@ultimat3/core';
|
|
2
|
-
import type { DurationInput } from './clock';
|
|
3
|
-
import type { EventLookup } from './steps';
|
|
4
|
-
export interface JobEvent {
|
|
5
|
-
readonly id: string;
|
|
6
|
-
readonly name: string;
|
|
7
|
-
readonly payload: unknown;
|
|
8
|
-
/** Ties the event to one waiting run — usually an entity id. */
|
|
9
|
-
readonly correlationKey?: string;
|
|
10
|
-
readonly publishedAt: number;
|
|
11
|
-
readonly expiresAt: number;
|
|
12
|
-
}
|
|
13
|
-
export interface PublishOptions {
|
|
14
|
-
readonly correlationKey?: string;
|
|
15
|
-
/** How long the event stays matchable. Default 7d — longer than any sane wait. */
|
|
16
|
-
readonly ttl?: DurationInput;
|
|
17
|
-
}
|
|
18
|
-
export interface EventBus extends EventLookup {
|
|
19
|
-
publish(name: string, payload: unknown, options?: PublishOptions): Promise<JobEvent>;
|
|
20
|
-
list(name?: string): Promise<readonly JobEvent[]>;
|
|
21
|
-
purgeExpired(): number;
|
|
22
|
-
size(): number;
|
|
23
|
-
}
|
|
24
|
-
export interface MemoryEventBusOptions {
|
|
25
|
-
readonly clock?: Clock;
|
|
26
|
-
readonly defaultTtl?: DurationInput;
|
|
27
|
-
readonly maxEvents?: number;
|
|
28
|
-
}
|
|
29
|
-
export declare function createMemoryEventBus(options?: MemoryEventBusOptions): EventBus;
|
|
30
|
-
/** Swapped at boot for the NATS/Redis-streams bus in a multi-node deployment. */
|
|
31
|
-
export declare function setEventBus(bus: EventBus): void;
|
|
32
|
-
export declare function eventBus(): EventBus;
|
|
33
|
-
/** The one function app code calls to unblock a waiting step. */
|
|
34
|
-
export declare function publishEvent(name: string, payload: unknown, options?: PublishOptions): Promise<JobEvent>;
|
|
35
|
-
//# sourceMappingURL=events.d.ts.map
|
package/src/events.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["events.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAE5C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3C,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,gEAAgE;IAChE,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IACjC,kFAAkF;IAClF,QAAQ,CAAC,GAAG,CAAC,EAAE,aAAa,CAAC;CAC9B;AAED,MAAM,WAAW,QAAS,SAAQ,WAAW;IAC3C,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;IACrF,IAAI,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,QAAQ,EAAE,CAAC,CAAC;IAClD,YAAY,IAAI,MAAM,CAAC;IACvB,IAAI,IAAI,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC;IACvB,QAAQ,CAAC,UAAU,CAAC,EAAE,aAAa,CAAC;IACpC,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,wBAAgB,oBAAoB,CAAC,OAAO,GAAE,qBAA0B,GAAG,QAAQ,CA0ElF;AAID,iFAAiF;AACjF,wBAAgB,WAAW,CAAC,GAAG,EAAE,QAAQ,GAAG,IAAI,CAE/C;AAED,wBAAgB,QAAQ,IAAI,QAAQ,CAEnC;AAED,iEAAiE;AACjE,wBAAgB,YAAY,CAC1B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,OAAO,EAChB,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,QAAQ,CAAC,CAEnB"}
|
package/src/events.js
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
// The event bus `step.waitForEvent` consumes. Events are stored, not just broadcast: a step
|
|
2
|
-
// that suspends at 12:00 and resumes at 12:00:30 must still see an event published at
|
|
3
|
-
// 12:00:10, so a fire-and-forget emitter would silently strand every waiting run.
|
|
4
|
-
import { logger, systemClock, uuid } from '@ultimat3/core';
|
|
5
|
-
import { nowMs, toMs } from './clock';
|
|
6
|
-
export function createMemoryEventBus(options = {}) {
|
|
7
|
-
const clock = options.clock ?? systemClock;
|
|
8
|
-
const defaultTtl = options.defaultTtl ?? 604_800_000;
|
|
9
|
-
const maxEvents = options.maxEvents ?? 10_000;
|
|
10
|
-
const events = new Map();
|
|
11
|
-
const purgeExpired = () => {
|
|
12
|
-
const at = nowMs(clock);
|
|
13
|
-
let removed = 0;
|
|
14
|
-
for (const [id, event] of events) {
|
|
15
|
-
if (event.expiresAt <= at) {
|
|
16
|
-
events.delete(id);
|
|
17
|
-
removed += 1;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return removed;
|
|
21
|
-
};
|
|
22
|
-
return {
|
|
23
|
-
publish(name, payload, publishOptions = {}) {
|
|
24
|
-
purgeExpired();
|
|
25
|
-
const at = nowMs(clock);
|
|
26
|
-
const event = {
|
|
27
|
-
id: uuid(),
|
|
28
|
-
name,
|
|
29
|
-
payload,
|
|
30
|
-
publishedAt: at,
|
|
31
|
-
expiresAt: at + toMs(publishOptions.ttl ?? defaultTtl),
|
|
32
|
-
...(publishOptions.correlationKey === undefined
|
|
33
|
-
? {}
|
|
34
|
-
: { correlationKey: publishOptions.correlationKey }),
|
|
35
|
-
};
|
|
36
|
-
events.set(event.id, event);
|
|
37
|
-
while (events.size > maxEvents) {
|
|
38
|
-
const oldest = events.keys().next();
|
|
39
|
-
if (oldest.done === true)
|
|
40
|
-
break;
|
|
41
|
-
events.delete(oldest.value);
|
|
42
|
-
}
|
|
43
|
-
logger.debug('jobs.event.published', {
|
|
44
|
-
event: name,
|
|
45
|
-
correlationKey: publishOptions.correlationKey ?? null,
|
|
46
|
-
});
|
|
47
|
-
return Promise.resolve(event);
|
|
48
|
-
},
|
|
49
|
-
/**
|
|
50
|
-
* Earliest matching event at or after `afterMs`, so a resumed step consumes events in
|
|
51
|
-
* publication order rather than jumping to the newest one.
|
|
52
|
-
*/
|
|
53
|
-
find(name, correlationKey, afterMs) {
|
|
54
|
-
const at = nowMs(clock);
|
|
55
|
-
let best;
|
|
56
|
-
for (const event of events.values()) {
|
|
57
|
-
if (event.name !== name)
|
|
58
|
-
continue;
|
|
59
|
-
if (event.expiresAt <= at)
|
|
60
|
-
continue;
|
|
61
|
-
if (event.publishedAt < afterMs)
|
|
62
|
-
continue;
|
|
63
|
-
if (correlationKey !== undefined && event.correlationKey !== correlationKey)
|
|
64
|
-
continue;
|
|
65
|
-
if (best === undefined || event.publishedAt < best.publishedAt)
|
|
66
|
-
best = event;
|
|
67
|
-
}
|
|
68
|
-
return Promise.resolve(best === undefined ? undefined : { payload: best.payload, publishedAt: best.publishedAt });
|
|
69
|
-
},
|
|
70
|
-
list(name) {
|
|
71
|
-
const all = [...events.values()]
|
|
72
|
-
.filter((event) => name === undefined || event.name === name)
|
|
73
|
-
.sort((a, b) => a.publishedAt - b.publishedAt);
|
|
74
|
-
return Promise.resolve(all);
|
|
75
|
-
},
|
|
76
|
-
purgeExpired,
|
|
77
|
-
size: () => events.size,
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
let ambientBus = createMemoryEventBus();
|
|
81
|
-
/** Swapped at boot for the NATS/Redis-streams bus in a multi-node deployment. */
|
|
82
|
-
export function setEventBus(bus) {
|
|
83
|
-
ambientBus = bus;
|
|
84
|
-
}
|
|
85
|
-
export function eventBus() {
|
|
86
|
-
return ambientBus;
|
|
87
|
-
}
|
|
88
|
-
/** The one function app code calls to unblock a waiting step. */
|
|
89
|
-
export function publishEvent(name, payload, options) {
|
|
90
|
-
return ambientBus.publish(name, payload, options);
|
|
91
|
-
}
|
|
92
|
-
//# sourceMappingURL=events.js.map
|
package/src/events.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"events.js","sourceRoot":"","sources":["events.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,sFAAsF;AACtF,kFAAkF;AAGlF,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAE3D,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAgCtC,MAAM,UAAU,oBAAoB,CAAC,OAAO,GAA0B,EAAE;IACtE,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,WAAW,CAA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7B,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,KAAK,SAAS,IAAI,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC;iBAC5D,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,GAAG,CAAC,CAAC,WAAW,CAAC,CAAC;YACjD,OAAO,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAC9B,CAAC;QAED,YAAY;QACZ,IAAI,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI;KACxB,CAAC;AACJ,CAAC;AAED,IAAI,UAAU,GAAa,oBAAoB,EAAE,CAAC;AAElD,iFAAiF;AACjF,MAAM,UAAU,WAAW,CAAC,GAAa;IACvC,UAAU,GAAG,GAAG,CAAC;AACnB,CAAC;AAED,MAAM,UAAU,QAAQ;IACtB,OAAO,UAAU,CAAC;AACpB,CAAC;AAED,iEAAiE;AACjE,MAAM,UAAU,YAAY,CAC1B,IAAY,EACZ,OAAgB,EAChB,OAAwB;IAExB,OAAO,UAAU,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;AACpD,CAAC"}
|
package/src/index.d.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
export type { ClaimedJob, ClaimOptions, ConflictPolicy, EnqueueRequest, EnqueueResult, JobDriver, JobFilter, JobIntrospection, JobRecord, JobState, NackOptions, QueueStats, } from './driver';
|
|
2
|
-
export { DEFAULT_QUEUE, DEFAULT_VISIBILITY_TIMEOUT_MS, jobDriver, setJobDriver, } from './driver';
|
|
3
|
-
export type { MemoryDriverOptions } from './driver-memory';
|
|
4
|
-
export { createMemoryDriver } from './driver-memory';
|
|
5
|
-
export type { NatsDriverOptions } from './driver-nats';
|
|
6
|
-
export { createNatsDriver } from './driver-nats';
|
|
7
|
-
export type { PgDriverOptions, PgExecutor } from './driver-pg';
|
|
8
|
-
export { createPgDriver, createPgLeader } from './driver-pg';
|
|
9
|
-
export { SQL_ACK, SQL_ADVISORY_UNLOCK, SQL_CLAIM, SQL_ENQUEUE, SQL_HEARTBEAT, SQL_JOBS_TABLE, SQL_NACK, SQL_STATS, SQL_STEP_GET, SQL_STEP_PUT, SQL_TRY_ADVISORY_LOCK, } from './driver-pg-sql';
|
|
10
|
-
export type { RedisDriverOptions } from './driver-redis';
|
|
11
|
-
export { createRedisDriver } from './driver-redis';
|
|
12
|
-
export type { JobErrorCode } from './errors';
|
|
13
|
-
export { DriverUnavailableError, IdempotencyRequiredError, JOB_ERROR_CODES, JobDuplicateError, JobMaxAttemptsError, JobsNotImplementedError, JobTimeoutError, OutboxNoTxError, StepDuplicateError, } from './errors';
|
|
14
|
-
export type { EventBus, JobEvent, MemoryEventBusOptions, PublishOptions } from './events';
|
|
15
|
-
export { createMemoryEventBus, eventBus, publishEvent, setEventBus } from './events';
|
|
16
|
-
export type { DeadLetterEntry, JobsManifest, JobTrace, QueueDepthReport, StepTrace, } from './inspect';
|
|
17
|
-
export { inspectDeadLetters, inspectJob, inspectJobList, inspectManifest, inspectQueues, retryFromStep, } from './inspect';
|
|
18
|
-
export type { AnyJobHandle, JobDefinition, JobHandle, JobRunArgs } from './job';
|
|
19
|
-
export { describeJobs, getJob, job, nameJobs, registeredJobs, resetJobs } from './job';
|
|
20
|
-
export type { Lease, LimitConfig, Limiter, LimitKey, LimitReason, LimitSnapshot, RateLimit, } from './limits';
|
|
21
|
-
export { createLimiter, NO_TENANT, tenantKeyFrom } from './limits';
|
|
22
|
-
export type { EnqueueOptions, JobsFacade, OutboxDeps, OutboxRecord, OutboxRelay, OutboxStore, RelayOptions, } from './outbox';
|
|
23
|
-
export { createJobsFacade, createMemoryOutboxStore, createOutboxRelay, enqueueInTx, SQL_OUTBOX_CLAIM, SQL_OUTBOX_MARK_PUBLISHED, SQL_OUTBOX_STAGE, SQL_OUTBOX_TABLE, } from './outbox';
|
|
24
|
-
export type { BackoffStrategy, Random, RetryDecision, RetryPolicy } from './retry';
|
|
25
|
-
export { backoffDelayMs, DEFAULT_RETRY, nextRetry, retrySchedule } from './retry';
|
|
26
|
-
export type { CatchUpPolicy, CronResolver, DispatchedOccurrence, LeaderElection, Scheduler, SchedulerOptions, SchedulerState, TaskDefinition, TaskEnqueueEntry, TaskHandle, } from './scheduler';
|
|
27
|
-
export { createMemorySchedulerState, createScheduler, getTask, nameTasks, registeredTasks, resetTasks, soleLeader, task, } from './scheduler';
|
|
28
|
-
export type { EventLookup, StepApi, StepRecord, StepRunner, StepRunnerOptions, StepStatus, StepStore, WaitForEventOptions, } from './steps';
|
|
29
|
-
export { createMemoryStepStore, createStepRunner, isStepSuspension, StepSuspension, } from './steps';
|
|
30
|
-
export type { ExecuteJobOptions, JobExecution, JobOutcome, Worker, WorkerOptions, WorkerStats, } from './worker';
|
|
31
|
-
export { createWorker, executeJob } from './worker';
|
|
32
|
-
//# sourceMappingURL=index.d.ts.map
|
package/src/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAEA,YAAY,EACV,UAAU,EACV,YAAY,EACZ,cAAc,EACd,cAAc,EACd,aAAa,EACb,SAAS,EACT,SAAS,EACT,gBAAgB,EAChB,SAAS,EACT,QAAQ,EACR,WAAW,EACX,UAAU,GACX,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,aAAa,EACb,6BAA6B,EAC7B,SAAS,EACT,YAAY,GACb,MAAM,UAAU,CAAC;AAClB,YAAY,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,YAAY,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,YAAY,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC/D,OAAO,EAAE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,SAAS,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACnE,YAAY,EACV,cAAc,EACd,UAAU,EACV,UAAU,EACV,YAAY,EACZ,WAAW,EACX,WAAW,EACX,YAAY,GACb,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,gBAAgB,EAChB,uBAAuB,EACvB,iBAAiB,EACjB,WAAW,EACX,gBAAgB,EAChB,yBAAyB,EACzB,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,UAAU,CAAC;AAClB,YAAY,EAAE,eAAe,EAAE,MAAM,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACnF,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAClF,YAAY,EACV,aAAa,EACb,YAAY,EACZ,oBAAoB,EACpB,cAAc,EACd,SAAS,EACT,gBAAgB,EAChB,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,UAAU,GACX,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,0BAA0B,EAC1B,eAAe,EACf,OAAO,EACP,SAAS,EACT,eAAe,EACf,UAAU,EACV,UAAU,EACV,IAAI,GACL,MAAM,aAAa,CAAC;AACrB,YAAY,EACV,WAAW,EACX,OAAO,EACP,UAAU,EACV,UAAU,EACV,iBAAiB,EACjB,UAAU,EACV,SAAS,EACT,mBAAmB,GACpB,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,qBAAqB,EACrB,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,GACf,MAAM,SAAS,CAAC;AACjB,YAAY,EACV,iBAAiB,EACjB,YAAY,EACZ,UAAU,EACV,MAAM,EACN,aAAa,EACb,WAAW,GACZ,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC"}
|
package/src/index.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
// Public API of @ultimat3/jobs. Explicit, no `export *`.
|
|
2
|
-
export { DEFAULT_QUEUE, DEFAULT_VISIBILITY_TIMEOUT_MS, jobDriver, setJobDriver, } from './driver';
|
|
3
|
-
export { createMemoryDriver } from './driver-memory';
|
|
4
|
-
export { createNatsDriver } from './driver-nats';
|
|
5
|
-
export { createPgDriver, createPgLeader } from './driver-pg';
|
|
6
|
-
export { SQL_ACK, SQL_ADVISORY_UNLOCK, SQL_CLAIM, SQL_ENQUEUE, SQL_HEARTBEAT, SQL_JOBS_TABLE, SQL_NACK, SQL_STATS, SQL_STEP_GET, SQL_STEP_PUT, SQL_TRY_ADVISORY_LOCK, } from './driver-pg-sql';
|
|
7
|
-
export { createRedisDriver } from './driver-redis';
|
|
8
|
-
export { DriverUnavailableError, IdempotencyRequiredError, JOB_ERROR_CODES, JobDuplicateError, JobMaxAttemptsError, JobsNotImplementedError, JobTimeoutError, OutboxNoTxError, StepDuplicateError, } from './errors';
|
|
9
|
-
export { createMemoryEventBus, eventBus, publishEvent, setEventBus } from './events';
|
|
10
|
-
export { inspectDeadLetters, inspectJob, inspectJobList, inspectManifest, inspectQueues, retryFromStep, } from './inspect';
|
|
11
|
-
export { describeJobs, getJob, job, nameJobs, registeredJobs, resetJobs } from './job';
|
|
12
|
-
export { createLimiter, NO_TENANT, tenantKeyFrom } from './limits';
|
|
13
|
-
export { createJobsFacade, createMemoryOutboxStore, createOutboxRelay, enqueueInTx, SQL_OUTBOX_CLAIM, SQL_OUTBOX_MARK_PUBLISHED, SQL_OUTBOX_STAGE, SQL_OUTBOX_TABLE, } from './outbox';
|
|
14
|
-
export { backoffDelayMs, DEFAULT_RETRY, nextRetry, retrySchedule } from './retry';
|
|
15
|
-
export { createMemorySchedulerState, createScheduler, getTask, nameTasks, registeredTasks, resetTasks, soleLeader, task, } from './scheduler';
|
|
16
|
-
export { createMemoryStepStore, createStepRunner, isStepSuspension, StepSuspension, } from './steps';
|
|
17
|
-
export { createWorker, executeJob } from './worker';
|
|
18
|
-
//# sourceMappingURL=index.js.map
|
package/src/index.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gBAAgB,GACjB,MAAM,UAAU,CAAC;AAElB,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAalF,OAAO,EACL,0BAA0B,EAC1B,eAAe,EACf,OAAO,EACP,SAAS,EACT,eAAe,EACf,UAAU,EACV,UAAU,EACV,IAAI,GACL,MAAM,aAAa,CAAC;AAWrB,OAAO,EACL,qBAAqB,EACrB,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,GACf,MAAM,SAAS,CAAC;AASjB,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC"}
|
package/src/inspect.d.ts
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import type { JobDriver, JobFilter, JobRecord, QueueStats } from './driver';
|
|
2
|
-
import type { Scheduler } from './scheduler';
|
|
3
|
-
import type { StepRecord } from './steps';
|
|
4
|
-
export interface QueueDepthReport {
|
|
5
|
-
readonly driver: string;
|
|
6
|
-
readonly queues: readonly QueueStats[];
|
|
7
|
-
readonly totals: {
|
|
8
|
-
readonly ready: number;
|
|
9
|
-
readonly delayed: number;
|
|
10
|
-
readonly running: number;
|
|
11
|
-
readonly suspended: number;
|
|
12
|
-
readonly dead: number;
|
|
13
|
-
};
|
|
14
|
-
/** Oldest claimable job across all queues, in ms. The autoscaling signal. */
|
|
15
|
-
readonly oldestReadyMs: number;
|
|
16
|
-
}
|
|
17
|
-
export declare function inspectQueues(driver: JobDriver): Promise<QueueDepthReport>;
|
|
18
|
-
export interface StepTrace {
|
|
19
|
-
readonly name: string;
|
|
20
|
-
readonly status: StepRecord['status'];
|
|
21
|
-
readonly startedAt: string;
|
|
22
|
-
readonly completedAt: string | null;
|
|
23
|
-
readonly wakeAt: string | null;
|
|
24
|
-
readonly durationMs: number | null;
|
|
25
|
-
readonly attempts: number;
|
|
26
|
-
readonly error: string | null;
|
|
27
|
-
}
|
|
28
|
-
export interface JobTrace {
|
|
29
|
-
readonly id: string;
|
|
30
|
-
readonly name: string;
|
|
31
|
-
readonly queue: string;
|
|
32
|
-
readonly state: JobRecord['state'];
|
|
33
|
-
readonly attempt: number;
|
|
34
|
-
readonly maxAttempts: number;
|
|
35
|
-
readonly idempotencyKey: string;
|
|
36
|
-
readonly runId: string;
|
|
37
|
-
readonly runAt: string;
|
|
38
|
-
readonly lastError: string | null;
|
|
39
|
-
readonly tenantId: string | null;
|
|
40
|
-
readonly steps: readonly StepTrace[];
|
|
41
|
-
/** Remaining retry delays in ms, jitter excluded. */
|
|
42
|
-
readonly retryDelaysMs: readonly number[];
|
|
43
|
-
}
|
|
44
|
-
export declare function inspectJob(driver: JobDriver, jobId: string): Promise<JobTrace | undefined>;
|
|
45
|
-
export declare function inspectJobList(driver: JobDriver, filter?: JobFilter): Promise<readonly JobRecord[]>;
|
|
46
|
-
export interface DeadLetterEntry {
|
|
47
|
-
readonly id: string;
|
|
48
|
-
readonly name: string;
|
|
49
|
-
readonly queue: string;
|
|
50
|
-
readonly attempt: number;
|
|
51
|
-
readonly lastError: string | null;
|
|
52
|
-
readonly failedAt: string;
|
|
53
|
-
readonly retryCommand: string;
|
|
54
|
-
}
|
|
55
|
-
export declare function inspectDeadLetters(driver: JobDriver, limit?: number): Promise<readonly DeadLetterEntry[]>;
|
|
56
|
-
/**
|
|
57
|
-
* Re-queue a job, optionally dropping one step's persisted result so it re-executes while
|
|
58
|
-
* everything before it replays from storage. This is why steps are stored, not just logged.
|
|
59
|
-
*/
|
|
60
|
-
export declare function retryFromStep(driver: JobDriver, jobId: string, stepName?: string): Promise<JobTrace | undefined>;
|
|
61
|
-
export interface JobsManifest {
|
|
62
|
-
readonly jobs: readonly {
|
|
63
|
-
readonly name: string;
|
|
64
|
-
readonly queue: string;
|
|
65
|
-
readonly attempts: number;
|
|
66
|
-
readonly backoff: string;
|
|
67
|
-
readonly concurrency: number | null;
|
|
68
|
-
readonly timeoutMs: number | null;
|
|
69
|
-
readonly retryDelaysMs: readonly number[];
|
|
70
|
-
}[];
|
|
71
|
-
readonly tasks: readonly {
|
|
72
|
-
readonly name: string;
|
|
73
|
-
readonly cron: string;
|
|
74
|
-
readonly tz: string;
|
|
75
|
-
readonly catchUp: string;
|
|
76
|
-
readonly nextRun: string | null;
|
|
77
|
-
readonly enqueues: readonly string[];
|
|
78
|
-
}[];
|
|
79
|
-
}
|
|
80
|
-
/** Feeds `x.manifest.json` and the MCP `jobs.list` tool. Generated facts, never prose. */
|
|
81
|
-
export declare function inspectManifest(scheduler?: Scheduler): JobsManifest;
|
|
82
|
-
//# sourceMappingURL=inspect.d.ts.map
|
package/src/inspect.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"inspect.d.ts","sourceRoot":"","sources":["inspect.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAI5E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1C,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,SAAS,UAAU,EAAE,CAAC;IACvC,QAAQ,CAAC,MAAM,EAAE;QACf,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;QACvB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;QACzB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;QACzB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;QAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;KACvB,CAAC;IACF,6EAA6E;IAC7E,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;CAChC;AAED,wBAAsB,aAAa,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAkBhF;AAED,MA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,IAAI,EAAE,MAAM,CAAC;QACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QACtB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;QACpB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;QACzB,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;QAChC,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;KACtC,EAAE,CAAC;CACL;AAED,0FAA0F;AAC1F,wBAAgB,eAAe,CAAC,SAAS,CAAC,EAAE,SAAS,GAAG,YAAY,CAoBnE"}
|
package/src/inspect.js
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
// Introspection for `/_x`, the CLI and MCP. Every function returns a plain JSON-serialisable
|
|
2
|
-
// object so `x jobs ... --json` and the MCP tool share one shape — an agent debugging a stuck
|
|
3
|
-
// queue reads exactly what the dashboard renders.
|
|
4
|
-
import { JobsNotImplementedError } from './errors';
|
|
5
|
-
import { registeredJobs } from './job';
|
|
6
|
-
import { retrySchedule } from './retry';
|
|
7
|
-
import { registeredTasks } from './scheduler';
|
|
8
|
-
export async function inspectQueues(driver) {
|
|
9
|
-
const queues = [...(await driver.stats())];
|
|
10
|
-
const totals = queues.reduce((acc, queue) => ({
|
|
11
|
-
ready: acc.ready + queue.ready,
|
|
12
|
-
delayed: acc.delayed + queue.delayed,
|
|
13
|
-
running: acc.running + queue.running,
|
|
14
|
-
suspended: acc.suspended + queue.suspended,
|
|
15
|
-
dead: acc.dead + queue.dead,
|
|
16
|
-
}), { ready: 0, delayed: 0, running: 0, suspended: 0, dead: 0 });
|
|
17
|
-
return {
|
|
18
|
-
driver: driver.name,
|
|
19
|
-
queues,
|
|
20
|
-
totals,
|
|
21
|
-
oldestReadyMs: queues.reduce((max, queue) => Math.max(max, queue.oldestReadyMs), 0),
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
const iso = (ms) => ms === undefined ? null : new Date(ms).toISOString();
|
|
25
|
-
function requireIntrospection(driver) {
|
|
26
|
-
if (driver.introspect === undefined) {
|
|
27
|
-
throw new JobsNotImplementedError({
|
|
28
|
-
feature: `introspection for the "${driver.name}" jobs driver`,
|
|
29
|
-
fix: 'use driver: "pg" (default) or "memory" — see docs/jobs/drivers.md',
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
return driver.introspect;
|
|
33
|
-
}
|
|
34
|
-
function toStepTrace(record) {
|
|
35
|
-
return {
|
|
36
|
-
name: record.name,
|
|
37
|
-
status: record.status,
|
|
38
|
-
startedAt: new Date(record.startedAt).toISOString(),
|
|
39
|
-
completedAt: iso(record.completedAt),
|
|
40
|
-
wakeAt: iso(record.wakeAt),
|
|
41
|
-
durationMs: record.completedAt === undefined ? null : record.completedAt - record.startedAt,
|
|
42
|
-
attempts: record.attempts,
|
|
43
|
-
error: record.error ?? null,
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
export async function inspectJob(driver, jobId) {
|
|
47
|
-
const record = await requireIntrospection(driver).job(jobId);
|
|
48
|
-
if (record === undefined)
|
|
49
|
-
return undefined;
|
|
50
|
-
const steps = await driver.steps.list(record.runId);
|
|
51
|
-
const handle = registeredJobs().find((candidate) => candidate.name === record.name);
|
|
52
|
-
return {
|
|
53
|
-
id: record.id,
|
|
54
|
-
name: record.name,
|
|
55
|
-
queue: record.queue,
|
|
56
|
-
state: record.state,
|
|
57
|
-
attempt: record.attempt,
|
|
58
|
-
maxAttempts: record.maxAttempts,
|
|
59
|
-
idempotencyKey: record.idempotencyKey,
|
|
60
|
-
runId: record.runId,
|
|
61
|
-
runAt: new Date(record.runAt).toISOString(),
|
|
62
|
-
lastError: record.lastError ?? null,
|
|
63
|
-
tenantId: record.tenantId ?? null,
|
|
64
|
-
steps: steps.map(toStepTrace),
|
|
65
|
-
retryDelaysMs: handle === undefined ? [] : [...retrySchedule(handle.retry)],
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
export function inspectJobList(driver, filter) {
|
|
69
|
-
return requireIntrospection(driver).list(filter);
|
|
70
|
-
}
|
|
71
|
-
export async function inspectDeadLetters(driver, limit = 100) {
|
|
72
|
-
const rows = await requireIntrospection(driver).deadLetters(limit);
|
|
73
|
-
return rows.map((record) => ({
|
|
74
|
-
id: record.id,
|
|
75
|
-
name: record.name,
|
|
76
|
-
queue: record.queue,
|
|
77
|
-
attempt: record.attempt,
|
|
78
|
-
lastError: record.lastError ?? null,
|
|
79
|
-
failedAt: new Date(record.updatedAt).toISOString(),
|
|
80
|
-
retryCommand: `x jobs retry ${record.id}`,
|
|
81
|
-
}));
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Re-queue a job, optionally dropping one step's persisted result so it re-executes while
|
|
85
|
-
* everything before it replays from storage. This is why steps are stored, not just logged.
|
|
86
|
-
*/
|
|
87
|
-
export async function retryFromStep(driver, jobId, stepName) {
|
|
88
|
-
await requireIntrospection(driver).requeue(jobId, stepName === undefined ? undefined : { fromStep: stepName });
|
|
89
|
-
return inspectJob(driver, jobId);
|
|
90
|
-
}
|
|
91
|
-
/** Feeds `x.manifest.json` and the MCP `jobs.list` tool. Generated facts, never prose. */
|
|
92
|
-
export function inspectManifest(scheduler) {
|
|
93
|
-
return {
|
|
94
|
-
jobs: registeredJobs().map((handle) => ({
|
|
95
|
-
name: handle.name,
|
|
96
|
-
queue: handle.queue,
|
|
97
|
-
attempts: handle.retry.attempts,
|
|
98
|
-
backoff: handle.retry.backoff ?? 'exponential',
|
|
99
|
-
concurrency: handle.concurrency ?? null,
|
|
100
|
-
timeoutMs: handle.timeoutMs ?? null,
|
|
101
|
-
retryDelaysMs: [...retrySchedule(handle.retry)],
|
|
102
|
-
})),
|
|
103
|
-
tasks: registeredTasks().map((handle) => ({
|
|
104
|
-
name: handle.name,
|
|
105
|
-
cron: handle.cron,
|
|
106
|
-
tz: handle.tz,
|
|
107
|
-
catchUp: handle.catchUp,
|
|
108
|
-
nextRun: scheduler === undefined ? null : scheduler.nextRunFor(handle).toISOString(),
|
|
109
|
-
enqueues: handle.entries().map(([job]) => job.name),
|
|
110
|
-
})),
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
//# sourceMappingURL=inspect.js.map
|
package/src/inspect.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"inspect.js","sourceRoot":"","sources":["inspect.ts"],"names":[],"mappings":"AAAA,6FAA6F;AAC7F,8FAA8F;AAC9F,kDAAkD;AAGlD,OAAO,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExC,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAiB9C,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,MAAiB;IACnD,MAAM,MAAM,GAAG,CAAC,GAAG,CAAC,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IAC3C,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAC1B,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;QACf,KAAK,EAAE,GAAG,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK;QAC9B,OAAO,EAAE,GAAG,CAAC,OAAO,GAAG,KAAK,CAAC,OAAO;QACpC,OAAO,EAAE,GAAG,CAAC,OAAO,GAAG,KAAK,CAAC,OAAO;QACpC,SAAS,EAAE,GAAG,CAAC,SAAS,GAAG,KAAK,CAAC,SAAS;QAC1C,IAAI,EAAE,GAAG,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI;KAC5B,CAAC,EACF,EAAE,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,CAC5D,CAAC;IACF,OAAO;QACL,MAAM,EAAE,MAAM,CAAC,IAAI;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AM,CAAC,KAAK,CAAC,OAAO,IAAI,aAAa;YAC9C,WAAW,EAAE,MAAM,CAAC,WAAW,IAAI,IAAI;YACvC,SAAS,EAAE,MAAM,CAAC,SAAS,IAAI,IAAI;YACnC,aAAa,EAAE,CAAC,GAAG,aAAa,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;SAChD,CAAC,CAAC;QACH,KAAK,EAAE,eAAe,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;YACxC,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,EAAE,EAAE,MAAM,CAAC,EAAE;YACb,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,OAAO,EAAE,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE;YACpF,QAAQ,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC;SACpD,CAAC,CAAC;KACJ,CAAC;AACJ,CAAC"}
|
package/src/job.d.ts
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import type { Ctx } from '@ultimat3/core';
|
|
2
|
-
import type { StandardSchemaV1 } from '@ultimat3/schema';
|
|
3
|
-
import type { DurationInput } from './clock';
|
|
4
|
-
import type { RetryPolicy } from './retry';
|
|
5
|
-
import { type BackoffStrategy } from './retry';
|
|
6
|
-
import type { StepApi } from './steps';
|
|
7
|
-
export interface JobRunArgs<I> {
|
|
8
|
-
readonly input: I;
|
|
9
|
-
readonly step: StepApi;
|
|
10
|
-
readonly ctx: Ctx;
|
|
11
|
-
/** 1-based. Assume at-least-once: never branch on `attempt === 1` for correctness. */
|
|
12
|
-
readonly attempt: number;
|
|
13
|
-
readonly jobId: string;
|
|
14
|
-
readonly runId: string;
|
|
15
|
-
}
|
|
16
|
-
export interface JobDefinition<I> {
|
|
17
|
-
/** Assigned by `x manifest` from the export name; only set by hand in tests. */
|
|
18
|
-
readonly name?: string;
|
|
19
|
-
readonly input: StandardSchemaV1<unknown, I>;
|
|
20
|
-
/** REQUIRED. See the file header — this is the whole point. */
|
|
21
|
-
readonly idempotencyKey: (input: I) => string;
|
|
22
|
-
readonly retry: RetryPolicy;
|
|
23
|
-
readonly queue?: string;
|
|
24
|
-
/** Max in-flight runs of THIS job across the fleet. Omit for the queue-wide cap. */
|
|
25
|
-
readonly concurrency?: number;
|
|
26
|
-
readonly timeout?: DurationInput;
|
|
27
|
-
run(args: JobRunArgs<I>): Promise<unknown>;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Methods (not function-typed properties) throughout, so `JobHandle<Specific>` is assignable
|
|
31
|
-
* to `AnyJobHandle` and heterogeneous handles can share a registry and a task's enqueue list.
|
|
32
|
-
*/
|
|
33
|
-
export interface JobHandle<I = unknown> {
|
|
34
|
-
readonly kind: 'job';
|
|
35
|
-
readonly name: string;
|
|
36
|
-
readonly queue: string;
|
|
37
|
-
readonly retry: RetryPolicy;
|
|
38
|
-
readonly concurrency: number | undefined;
|
|
39
|
-
readonly timeoutMs: number | undefined;
|
|
40
|
-
readonly input: StandardSchemaV1<unknown, I>;
|
|
41
|
-
parse(raw: unknown): I;
|
|
42
|
-
idempotencyKeyFor(input: I): string;
|
|
43
|
-
run(args: JobRunArgs<I>): Promise<unknown>;
|
|
44
|
-
}
|
|
45
|
-
export type AnyJobHandle = JobHandle<unknown>;
|
|
46
|
-
export declare function job<I>(definition: JobDefinition<I>): JobHandle<I>;
|
|
47
|
-
/**
|
|
48
|
-
* Called by generated code with `{ onboardOrg, sendDigest }` so queue rows carry the export
|
|
49
|
-
* name rather than a positional id. Enqueue works either way; the name is for humans.
|
|
50
|
-
*/
|
|
51
|
-
export declare function nameJobs(record: Readonly<Record<string, AnyJobHandle>>): void;
|
|
52
|
-
export declare function getJob(name: string): AnyJobHandle | undefined;
|
|
53
|
-
export declare function registeredJobs(): readonly AnyJobHandle[];
|
|
54
|
-
export declare function resetJobs(): void;
|
|
55
|
-
/**
|
|
56
|
-
* Registered jobs as the manifest, the `/_x` jobs panel and the MCP dev server need them.
|
|
57
|
-
* Name-sorted and JSON-safe because `x.manifest.json` is committed and diffed — an
|
|
58
|
-
* iteration-order-dependent field would show up as a spurious change on every build.
|
|
59
|
-
* `steps` stays in declaration order: it is a sequence, not a set.
|
|
60
|
-
*/
|
|
61
|
-
export declare function describeJobs(): readonly {
|
|
62
|
-
readonly name: string;
|
|
63
|
-
readonly input: unknown;
|
|
64
|
-
readonly queue: string;
|
|
65
|
-
readonly retry: {
|
|
66
|
-
readonly attempts: number;
|
|
67
|
-
readonly backoff: BackoffStrategy;
|
|
68
|
-
};
|
|
69
|
-
readonly steps: readonly string[];
|
|
70
|
-
}[];
|
|
71
|
-
//# sourceMappingURL=job.d.ts.map
|
package/src/job.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"job.d.ts","sourceRoot":"","sources":["job.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAE1C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEzD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAI7C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAE,KAAK,eAAe,EAAiB,MAAM,SAAS,CAAC;AAC9D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAEvC,MAAM,WAAW,UAAU,CAAC,CAAC;IAC3B,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;IAClB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC;IA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AC,GAAG,MAAM,CAAC;IACpC,GAAG,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAC5C;AAED,MAAM,MAAM,YAAY,GAAG,SAAS,CAAC,OAAO,CAAC,CAAC;AAK9C,wBAAgB,GAAG,CAAC,CAAC,EAAE,UAAU,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAyCjE;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,GAAG,IAAI,CAQ7E;AAED,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS,CAE7D;AAED,wBAAgB,cAAc,IAAI,SAAS,YAAY,EAAE,CAExD;AAED,wBAAgB,SAAS,IAAI,IAAI,CAGhC;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,IAAI,SAAS;IACvC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE;QAAE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,OAAO,EAAE,eAAe,CAAA;KAAE,CAAC;IACjF,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;CACnC,EAAE,CAaF"}
|
package/src/job.js
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
// The `job` primitive: durable background work. The shape is the contract's shape exactly.
|
|
2
|
-
//
|
|
3
|
-
// `idempotencyKey` is NON-OPTIONAL in the type. Queues deliver at least once — network
|
|
4
|
-
// partitions, visibility-timeout expiry and outbox relays all replay — so "did this already
|
|
5
|
-
// run?" is a question every job must answer. Making it optional means the answer is usually
|
|
6
|
-
// "nobody thought about it", and the bug (two charges, two welcome emails, two provisioned
|
|
7
|
-
// orgs) surfaces in production under load, never in a test. Requiring it by construction
|
|
8
|
-
// deletes that class of bug: there is no way to define a job that cannot be deduped.
|
|
9
|
-
import { assert } from '@ultimat3/core';
|
|
10
|
-
import { parse } from '@ultimat3/schema';
|
|
11
|
-
import { toMs } from './clock';
|
|
12
|
-
import { DEFAULT_QUEUE } from './driver';
|
|
13
|
-
import { IdempotencyRequiredError } from './errors';
|
|
14
|
-
import { DEFAULT_RETRY } from './retry';
|
|
15
|
-
const registry = new Map();
|
|
16
|
-
let anonymous = 0;
|
|
17
|
-
export function job(definition) {
|
|
18
|
-
anonymous += 1;
|
|
19
|
-
const name = definition.name ?? `anonymous-job-${anonymous}`;
|
|
20
|
-
// Runtime backstop for generated code and JS callers; TS already forbids omitting it.
|
|
21
|
-
if (typeof definition.idempotencyKey !== 'function') {
|
|
22
|
-
throw new IdempotencyRequiredError({ job: name });
|
|
23
|
-
}
|
|
24
|
-
assert(definition.retry.attempts >= 1, `job "${name}" needs retry.attempts >= 1, got ${String(definition.retry.attempts)}`, `set retry: { attempts: 1 } or higher on job("${name}") — 0 attempts means the job is never executed at all, not that it never retries`);
|
|
25
|
-
const handle = {
|
|
26
|
-
kind: 'job',
|
|
27
|
-
name,
|
|
28
|
-
queue: definition.queue ?? DEFAULT_QUEUE,
|
|
29
|
-
retry: { ...DEFAULT_RETRY, ...definition.retry },
|
|
30
|
-
concurrency: definition.concurrency,
|
|
31
|
-
timeoutMs: definition.timeout === undefined ? undefined : toMs(definition.timeout),
|
|
32
|
-
input: definition.input,
|
|
33
|
-
parse(raw) {
|
|
34
|
-
return parse(definition.input, raw);
|
|
35
|
-
},
|
|
36
|
-
idempotencyKeyFor(input) {
|
|
37
|
-
const key = definition.idempotencyKey(input);
|
|
38
|
-
assert(typeof key === 'string' && key.length > 0, `job "${name}" idempotencyKey returned an empty string`, `return a non-empty stable key from job("${name}").idempotencyKey — an empty key makes every enqueue look like a duplicate of every other`);
|
|
39
|
-
return key;
|
|
40
|
-
},
|
|
41
|
-
run(args) {
|
|
42
|
-
return definition.run(args);
|
|
43
|
-
},
|
|
44
|
-
};
|
|
45
|
-
registry.set(name, handle);
|
|
46
|
-
return handle;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Called by generated code with `{ onboardOrg, sendDigest }` so queue rows carry the export
|
|
50
|
-
* name rather than a positional id. Enqueue works either way; the name is for humans.
|
|
51
|
-
*/
|
|
52
|
-
export function nameJobs(record) {
|
|
53
|
-
for (const [exportName, handle] of Object.entries(record)) {
|
|
54
|
-
if (handle.name === exportName)
|
|
55
|
-
continue;
|
|
56
|
-
registry.delete(handle.name);
|
|
57
|
-
// The caller holds a reference to this exact object, so rebind its name in place.
|
|
58
|
-
Object.defineProperty(handle, 'name', { value: exportName, configurable: true });
|
|
59
|
-
registry.set(exportName, handle);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
export function getJob(name) {
|
|
63
|
-
return registry.get(name);
|
|
64
|
-
}
|
|
65
|
-
export function registeredJobs() {
|
|
66
|
-
return [...registry.values()].sort((a, b) => a.name.localeCompare(b.name));
|
|
67
|
-
}
|
|
68
|
-
export function resetJobs() {
|
|
69
|
-
registry.clear();
|
|
70
|
-
anonymous = 0;
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Registered jobs as the manifest, the `/_x` jobs panel and the MCP dev server need them.
|
|
74
|
-
* Name-sorted and JSON-safe because `x.manifest.json` is committed and diffed — an
|
|
75
|
-
* iteration-order-dependent field would show up as a spurious change on every build.
|
|
76
|
-
* `steps` stays in declaration order: it is a sequence, not a set.
|
|
77
|
-
*/
|
|
78
|
-
export function describeJobs() {
|
|
79
|
-
return registeredJobs().map((handle) => ({
|
|
80
|
-
name: handle.name,
|
|
81
|
-
input: describeSchema(handle.input),
|
|
82
|
-
queue: handle.queue,
|
|
83
|
-
retry: {
|
|
84
|
-
attempts: handle.retry.attempts,
|
|
85
|
-
backoff: handle.retry.backoff ?? DEFAULT_RETRY.backoff,
|
|
86
|
-
},
|
|
87
|
-
// Empty by design: step names are chosen inside `run()` at execution time, so they are
|
|
88
|
-
// not statically knowable. `inspect(name)` reports the steps an actual run recorded.
|
|
89
|
-
steps: [],
|
|
90
|
-
}));
|
|
91
|
-
}
|
|
92
|
-
/** Best-effort JSON view of a Standard Schema; the vendor decides how much it exposes. */
|
|
93
|
-
function describeSchema(schema) {
|
|
94
|
-
if (schema === null || typeof schema !== 'object')
|
|
95
|
-
return null;
|
|
96
|
-
const vendor = schema['~standard'];
|
|
97
|
-
return { vendor: vendor?.vendor ?? 'unknown' };
|
|
98
|
-
}
|
|
99
|
-
//# sourceMappingURL=job.js.map
|
package/src/job.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"job.js","sourceRoot":"","sources":["job.ts"],"names":[],"mappings":"AAAA,2FAA2F;AAC3F,EAAE;AACF,uFAAuF;AACvF,4FAA4F;AAC5F,4FAA4F;AAC5F,2FAA2F;AAC3F,yFAAyF;AACzF,qFAAqF;AAGrF,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAExC,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAEzC,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,wBAAwB,EAAE,MAAM,UAAU,CAAC;AAEpD,OAAO,EAAwB,aAAa,EAAE,MAAM,SAAS,CAAC;AA8C9D,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAwB,CAAC;AACjD,IAAI,SAAS,GAAG,CAAC,CAAC;AAElB,MAAM,UAAU,GAAG,CAAI,UAA4B;IACjD,SAAS,IAAI,CAAC,CAAC;IACf,MAAM,IAAI,GAAG,UAAU,CAAC,IAAI,IAAI,iBAAiB,SAAS,EAAE,CAAC;IAE7D,sFAAsF;IACtF,IAAI,OA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