@x-otto/jobs 0.0.0-stage → 0.4.0-beta.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/dist/build-revision.json +4 -0
- package/dist/index.d.ts +297 -0
- package/dist/index.js +3396 -0
- package/package.json +27 -4
- package/README.md +0 -3
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
import * as _$_x_otto_kernel0 from "@x-otto/kernel";
|
|
2
|
+
import { Clock, DetachedProducerFactory, JobAdmin, JobAttachment, JobAttribution, JobCancelCause, JobDiagnostics, JobKind, JobOutcome, JobProducer, JobPurpose, JobQueuePhase, JobRegistry, JobReleaseLocator, JobRetention, JobSettledListener, JobSnapshot, JobSnapshotListener, JobSpec, OwnerJobView, PendingJobDetail, PlanItem, PlanItemView, Ports, Random, ReleasePhase, SessionWorkFence } from "@x-otto/kernel";
|
|
3
|
+
import * as _$_x_otto_universal0 from "@x-otto/universal";
|
|
4
|
+
|
|
5
|
+
//#region src/component.d.ts
|
|
6
|
+
interface JobsComponentOptions {
|
|
7
|
+
ports: Ports;
|
|
8
|
+
cancelGraceMs?: number;
|
|
9
|
+
releaseTimeoutMs?: number;
|
|
10
|
+
disposeGraceMs?: number;
|
|
11
|
+
maxRetained?: number;
|
|
12
|
+
detachedProducers?: DetachedProducerFactory;
|
|
13
|
+
}
|
|
14
|
+
declare const Jobs: _$_x_otto_universal0.ComponentDefinition<JobsComponentOptions>;
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/plans/plan-section.d.ts
|
|
17
|
+
declare const PLAN_SECTION_BUDGET_BYTES = 1024;
|
|
18
|
+
declare function renderPlan(items: readonly PlanItem[], budgetBytes?: number, views?: readonly PlanItemView[]): string | undefined;
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region src/ports.d.ts
|
|
21
|
+
interface JobTimerHandle {
|
|
22
|
+
readonly id: unknown;
|
|
23
|
+
}
|
|
24
|
+
interface JobTimer {
|
|
25
|
+
set(callback: () => void, intervalMs: number): JobTimerHandle;
|
|
26
|
+
dispose(handle: JobTimerHandle): void;
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region src/jobs/registry-types.d.ts
|
|
30
|
+
type CancelOutcome = {
|
|
31
|
+
kind: 'pending';
|
|
32
|
+
} | {
|
|
33
|
+
kind: 'failed';
|
|
34
|
+
error: unknown;
|
|
35
|
+
};
|
|
36
|
+
interface CancelAttempt {
|
|
37
|
+
cause: JobCancelCause;
|
|
38
|
+
graceMs: number;
|
|
39
|
+
settled: Promise<void>;
|
|
40
|
+
outcome: CancelOutcome;
|
|
41
|
+
}
|
|
42
|
+
type JobAdmission = {
|
|
43
|
+
accepted: true;
|
|
44
|
+
workId?: string;
|
|
45
|
+
} | {
|
|
46
|
+
accepted: false;
|
|
47
|
+
reason: 'rejected' | 'unconfirmed';
|
|
48
|
+
eventId?: string;
|
|
49
|
+
detail?: string;
|
|
50
|
+
};
|
|
51
|
+
interface JobReleaser {
|
|
52
|
+
producer: JobProducer;
|
|
53
|
+
mode: 'terminate' | 'detach';
|
|
54
|
+
}
|
|
55
|
+
type JobEntryState = 'running' | 'settled';
|
|
56
|
+
interface JobEntry {
|
|
57
|
+
id: string;
|
|
58
|
+
kind: JobKind;
|
|
59
|
+
label: string;
|
|
60
|
+
owner?: string;
|
|
61
|
+
subjectId?: string;
|
|
62
|
+
resultSeq?: number;
|
|
63
|
+
model?: string;
|
|
64
|
+
effort?: string;
|
|
65
|
+
provider?: string;
|
|
66
|
+
queuePhase?: JobQueuePhase;
|
|
67
|
+
itemIds?: readonly string[];
|
|
68
|
+
attribution?: JobAttribution;
|
|
69
|
+
createdAt: number;
|
|
70
|
+
state: JobEntryState;
|
|
71
|
+
completedAt?: number;
|
|
72
|
+
purpose: JobPurpose;
|
|
73
|
+
attachment: JobAttachment;
|
|
74
|
+
retention: JobRetention;
|
|
75
|
+
originTurn?: number;
|
|
76
|
+
jobKey?: string;
|
|
77
|
+
workId?: string;
|
|
78
|
+
stageAttemptId?: string;
|
|
79
|
+
outputRef?: string;
|
|
80
|
+
outcome?: JobOutcome;
|
|
81
|
+
release: ReleasePhase;
|
|
82
|
+
releaseError?: unknown;
|
|
83
|
+
releaseLocator?: JobReleaseLocator;
|
|
84
|
+
releaseUncertain?: true;
|
|
85
|
+
releasing?: Promise<void>;
|
|
86
|
+
diagnostics?: JobDiagnostics;
|
|
87
|
+
producer?: JobProducer;
|
|
88
|
+
releaser?: JobReleaser;
|
|
89
|
+
cancelAttempt?: CancelAttempt;
|
|
90
|
+
evicted: boolean;
|
|
91
|
+
reported: boolean;
|
|
92
|
+
waiters: Set<() => void>;
|
|
93
|
+
deadlineTimer?: ReturnType<typeof setTimeout>;
|
|
94
|
+
lastProgressAt?: number;
|
|
95
|
+
progressCount?: number;
|
|
96
|
+
rerun?: () => JobSpec;
|
|
97
|
+
dispose: () => Promise<void>;
|
|
98
|
+
}
|
|
99
|
+
interface JobAcceptance {
|
|
100
|
+
jobId: string;
|
|
101
|
+
jobKey: string;
|
|
102
|
+
purpose: JobPurpose;
|
|
103
|
+
kind: JobKind;
|
|
104
|
+
label: string;
|
|
105
|
+
attachment: JobAttachment;
|
|
106
|
+
owner?: string;
|
|
107
|
+
originTurn?: number;
|
|
108
|
+
workId?: string;
|
|
109
|
+
stageAttemptId?: string;
|
|
110
|
+
}
|
|
111
|
+
type TaskListenerSource = 'change' | 'settled' | 'release' | 'dispose' | 'fence';
|
|
112
|
+
interface JobRegistryImplOptions {
|
|
113
|
+
timer?: JobTimer;
|
|
114
|
+
random?: Random;
|
|
115
|
+
clock: Clock;
|
|
116
|
+
onStart?: JobSnapshotListener;
|
|
117
|
+
cancelGraceMs?: number;
|
|
118
|
+
releaseTimeoutMs?: number;
|
|
119
|
+
disposeGraceMs?: number;
|
|
120
|
+
maxRetained?: number;
|
|
121
|
+
maxRetainedTotal?: number;
|
|
122
|
+
onRelease?: JobSettledListener;
|
|
123
|
+
detachedProducers?: DetachedProducerFactory;
|
|
124
|
+
onListenerError?: (error: unknown, source: TaskListenerSource) => void;
|
|
125
|
+
onAccept?: (accepted: JobAcceptance) => Promise<boolean | JobAdmission>;
|
|
126
|
+
admissionGate?: () => boolean | 'queue';
|
|
127
|
+
attributionOf?: (sessionId: string, itemIds: readonly string[]) => JobAttribution | undefined;
|
|
128
|
+
onNotStarted?: (accepted: JobAcceptance, detail?: JobAdmission) => void | Promise<void>;
|
|
129
|
+
onStartFailed?: (accepted: JobAcceptance, error: unknown) => void | Promise<void>;
|
|
130
|
+
generateJobKey?: () => string;
|
|
131
|
+
jobAbsoluteTimeMs?: () => number;
|
|
132
|
+
jobProgressTimeMs?: () => number;
|
|
133
|
+
durableEventsOf?: (owner: string) => Promise<readonly _$_x_otto_kernel0.TrajectoryEvent[]>;
|
|
134
|
+
inheritedOwnerOf?: (owner: string) => boolean;
|
|
135
|
+
resultSeqOf?: (subjectId: string) => number | undefined;
|
|
136
|
+
}
|
|
137
|
+
//#endregion
|
|
138
|
+
//#region src/jobs/registry-state.d.ts
|
|
139
|
+
declare class JobRegistryState {
|
|
140
|
+
listenerError: ((error: unknown, source: TaskListenerSource) => void) | undefined;
|
|
141
|
+
readonly jobs: Map<string, JobEntry>;
|
|
142
|
+
readonly closingOwners: Set<string>;
|
|
143
|
+
readonly closingStages: Map<string, Set<string>>;
|
|
144
|
+
readonly stageRestoreBarriers: Map<string, Promise<void>>;
|
|
145
|
+
readonly stageRestoreResolvers: Map<string, () => void>;
|
|
146
|
+
readonly pendingAdmissions: Map<string, Set<Promise<void>>>;
|
|
147
|
+
readonly counters: Map<string, number>;
|
|
148
|
+
readonly listeners: Set<JobSettledListener>;
|
|
149
|
+
readonly changeListeners: Set<JobSnapshotListener>;
|
|
150
|
+
progressTimer: JobTimerHandle | undefined;
|
|
151
|
+
disposed: boolean;
|
|
152
|
+
disposeGraceMs: number | undefined;
|
|
153
|
+
}
|
|
154
|
+
//#endregion
|
|
155
|
+
//#region src/jobs/registry.d.ts
|
|
156
|
+
declare class JobRegistryImpl implements JobRegistry {
|
|
157
|
+
#private;
|
|
158
|
+
private readonly state;
|
|
159
|
+
private readonly clock;
|
|
160
|
+
private readonly timer;
|
|
161
|
+
private readonly random;
|
|
162
|
+
private readonly generateJobKey;
|
|
163
|
+
private readonly onStart;
|
|
164
|
+
private readonly onRelease;
|
|
165
|
+
private readonly onListenerError;
|
|
166
|
+
private readonly cancelGraceMs;
|
|
167
|
+
private readonly releaseTimeoutMs;
|
|
168
|
+
private readonly disposeGraceMs;
|
|
169
|
+
private readonly maxRetained;
|
|
170
|
+
private readonly maxRetainedTotal;
|
|
171
|
+
private readonly admissionGate;
|
|
172
|
+
private readonly onAccept;
|
|
173
|
+
private readonly attributionOf;
|
|
174
|
+
private readonly onNotStarted;
|
|
175
|
+
private readonly onStartFailed;
|
|
176
|
+
private readonly jobAbsoluteTimeMs;
|
|
177
|
+
private readonly jobProgressTimeMs;
|
|
178
|
+
private readonly detachedProducers;
|
|
179
|
+
private readonly detachedProducersLinked;
|
|
180
|
+
private readonly admission;
|
|
181
|
+
private readonly cancelOps;
|
|
182
|
+
private readonly releaseOps;
|
|
183
|
+
private readonly retentionOps;
|
|
184
|
+
private readonly views;
|
|
185
|
+
private readonly recoveredOwners;
|
|
186
|
+
private readonly forgottenOwners;
|
|
187
|
+
private readonly recoveryInFlight;
|
|
188
|
+
private readonly durableEventsOf;
|
|
189
|
+
private readonly resultSeqOf;
|
|
190
|
+
private readonly inheritedOwnerOf;
|
|
191
|
+
constructor(options: JobRegistryImplOptions, state?: JobRegistryState);
|
|
192
|
+
start(spec: JobSpec): Promise<JobSnapshot>;
|
|
193
|
+
private notifyNotStarted;
|
|
194
|
+
forOwner(owner: string): OwnerJobView;
|
|
195
|
+
private releaseOwner;
|
|
196
|
+
admin(): JobAdmin;
|
|
197
|
+
private createDetached;
|
|
198
|
+
private nextDetachedId;
|
|
199
|
+
private registerDetached;
|
|
200
|
+
private recoverSettledFor;
|
|
201
|
+
private reasonForInheritedOwner;
|
|
202
|
+
private foldDurableSettled;
|
|
203
|
+
private attachRecoveredReleaser;
|
|
204
|
+
private reserveDetachedId;
|
|
205
|
+
private addDetached;
|
|
206
|
+
forgetSettled(owner: string): number;
|
|
207
|
+
private rerun;
|
|
208
|
+
disposeAll(): Promise<void>;
|
|
209
|
+
private getForOwner;
|
|
210
|
+
private readForOwner;
|
|
211
|
+
private killForOwner;
|
|
212
|
+
private waitForOwner;
|
|
213
|
+
private onDone;
|
|
214
|
+
private onChange;
|
|
215
|
+
private applyUpdate;
|
|
216
|
+
private withProcessIdentity;
|
|
217
|
+
private expectVisible;
|
|
218
|
+
private retimeForQueuePhase;
|
|
219
|
+
private armAbsoluteDeadline;
|
|
220
|
+
private trackProgress;
|
|
221
|
+
private ensureProgressTimer;
|
|
222
|
+
private stopProgressTimer;
|
|
223
|
+
private stopProgressTimerIfNoTrackedJob;
|
|
224
|
+
private pollProgress;
|
|
225
|
+
private expireForStall;
|
|
226
|
+
private expireAbsoluteDeadline;
|
|
227
|
+
private settle;
|
|
228
|
+
private retryReleaseForOwner;
|
|
229
|
+
private emitChange;
|
|
230
|
+
private emitChangeIfPresent;
|
|
231
|
+
private detach;
|
|
232
|
+
private announceSettled;
|
|
233
|
+
}
|
|
234
|
+
//#endregion
|
|
235
|
+
//#region src/jobs/registry-support.d.ts
|
|
236
|
+
declare const DEFAULT_CANCEL_GRACE_MS = 5000;
|
|
237
|
+
//#endregion
|
|
238
|
+
//#region src/slot-queue/slot-wait.d.ts
|
|
239
|
+
declare const SLOT_WAIT_FIRST_DELAY_MS = 500;
|
|
240
|
+
declare const SLOT_WAIT_MAX_DELAY_MS = 5000;
|
|
241
|
+
interface SlotWaitOptions {
|
|
242
|
+
startsPerRound?: number;
|
|
243
|
+
isEnabled?: () => boolean;
|
|
244
|
+
sleep?: (milliseconds: number) => Promise<void>;
|
|
245
|
+
}
|
|
246
|
+
declare const slotWaitDelayOf: (attempt: number) => number;
|
|
247
|
+
//#endregion
|
|
248
|
+
//#region src/slot-queue/slot-queue.d.ts
|
|
249
|
+
type QueuedResumeOutcome = 'started' | 'queued' | 'failed';
|
|
250
|
+
interface QueuedEntry {
|
|
251
|
+
jobId: string;
|
|
252
|
+
parentSessionId: string;
|
|
253
|
+
resume(): Promise<QueuedResumeOutcome>;
|
|
254
|
+
abandon(cause: JobCancelCause): void;
|
|
255
|
+
}
|
|
256
|
+
declare class SlotQueue {
|
|
257
|
+
private entries;
|
|
258
|
+
private readonly options;
|
|
259
|
+
private draining;
|
|
260
|
+
private timer;
|
|
261
|
+
private wake;
|
|
262
|
+
private running;
|
|
263
|
+
private disposed;
|
|
264
|
+
constructor(options?: SlotWaitOptions);
|
|
265
|
+
isEnabled(): boolean;
|
|
266
|
+
depth(): number;
|
|
267
|
+
enqueue(entry: QueuedEntry): void;
|
|
268
|
+
remove(jobId: string): boolean;
|
|
269
|
+
drain(limit?: number): Promise<readonly string[]>;
|
|
270
|
+
dispose(): void;
|
|
271
|
+
private drainEntries;
|
|
272
|
+
private ensureRunning;
|
|
273
|
+
private run;
|
|
274
|
+
private pause;
|
|
275
|
+
}
|
|
276
|
+
//#endregion
|
|
277
|
+
//#region src/jobs/work-fence.d.ts
|
|
278
|
+
interface JobWorkFence extends SessionWorkFence {
|
|
279
|
+
pendingResults(sessionId: string, uptoTurn?: number): number;
|
|
280
|
+
pendingDetail(sessionId: string, uptoTurn?: number): PendingJobDetail | undefined;
|
|
281
|
+
inFlightResultKeys(sessionId: string, uptoTurn?: number): ReadonlySet<string>;
|
|
282
|
+
services(sessionId: string): number;
|
|
283
|
+
resources(sessionId: string): number;
|
|
284
|
+
pendingResources(sessionId: string): number;
|
|
285
|
+
changed(sessionId: string | undefined): void;
|
|
286
|
+
}
|
|
287
|
+
declare function createJobWorkFence(registry: () => JobRegistry, onListenerError?: (error: unknown, source: 'fence') => void): JobWorkFence;
|
|
288
|
+
//#endregion
|
|
289
|
+
//#region src/jobs/release-sweep.d.ts
|
|
290
|
+
interface ReleaseSweepResult {
|
|
291
|
+
readonly retried: number;
|
|
292
|
+
readonly confirmed: number;
|
|
293
|
+
readonly failed: number;
|
|
294
|
+
}
|
|
295
|
+
declare function retryFailedReleases(registry: JobRegistry): Promise<ReleaseSweepResult>;
|
|
296
|
+
//#endregion
|
|
297
|
+
export { DEFAULT_CANCEL_GRACE_MS, JobRegistryImpl, type JobWorkFence, Jobs, type JobsComponentOptions, PLAN_SECTION_BUDGET_BYTES, type QueuedEntry, type QueuedResumeOutcome, type ReleaseSweepResult, SLOT_WAIT_FIRST_DELAY_MS, SLOT_WAIT_MAX_DELAY_MS, SlotQueue, type SlotWaitOptions, createJobWorkFence, renderPlan, retryFailedReleases, slotWaitDelayOf };
|