duron 0.3.0-beta.8 → 0.3.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/action-job.d.ts +33 -2
- package/dist/action-job.d.ts.map +1 -1
- package/dist/action-job.js +93 -26
- package/dist/action-manager.d.ts +44 -2
- package/dist/action-manager.d.ts.map +1 -1
- package/dist/action-manager.js +64 -3
- package/dist/action.d.ts +388 -7
- package/dist/action.d.ts.map +1 -1
- package/dist/action.js +44 -23
- package/dist/adapters/adapter.d.ts +365 -8
- package/dist/adapters/adapter.d.ts.map +1 -1
- package/dist/adapters/adapter.js +221 -15
- package/dist/adapters/postgres/base.d.ts +184 -6
- package/dist/adapters/postgres/base.d.ts.map +1 -1
- package/dist/adapters/postgres/base.js +436 -75
- package/dist/adapters/postgres/pglite.d.ts +37 -0
- package/dist/adapters/postgres/pglite.d.ts.map +1 -1
- package/dist/adapters/postgres/pglite.js +38 -0
- package/dist/adapters/postgres/postgres.d.ts +35 -0
- package/dist/adapters/postgres/postgres.d.ts.map +1 -1
- package/dist/adapters/postgres/postgres.js +42 -0
- package/dist/adapters/postgres/schema.d.ts +150 -37
- package/dist/adapters/postgres/schema.d.ts.map +1 -1
- package/dist/adapters/postgres/schema.default.d.ts +151 -38
- package/dist/adapters/postgres/schema.default.d.ts.map +1 -1
- package/dist/adapters/postgres/schema.default.js +2 -2
- package/dist/adapters/postgres/schema.js +60 -23
- package/dist/adapters/schemas.d.ts +124 -80
- package/dist/adapters/schemas.d.ts.map +1 -1
- package/dist/adapters/schemas.js +139 -26
- package/dist/client.d.ts +426 -22
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +370 -20
- package/dist/constants.js +6 -0
- package/dist/errors.d.ts +166 -9
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +189 -19
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/server.d.ts +99 -37
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +84 -25
- package/dist/step-manager.d.ts +111 -4
- package/dist/step-manager.d.ts.map +1 -1
- package/dist/step-manager.js +411 -75
- package/dist/telemetry/index.d.ts +1 -4
- package/dist/telemetry/index.d.ts.map +1 -1
- package/dist/telemetry/index.js +2 -4
- package/dist/telemetry/local-span-exporter.d.ts +56 -0
- package/dist/telemetry/local-span-exporter.d.ts.map +1 -0
- package/dist/telemetry/local-span-exporter.js +118 -0
- package/dist/utils/p-retry.d.ts +5 -0
- package/dist/utils/p-retry.d.ts.map +1 -1
- package/dist/utils/p-retry.js +8 -0
- package/dist/utils/wait-for-abort.d.ts +1 -0
- package/dist/utils/wait-for-abort.d.ts.map +1 -1
- package/dist/utils/wait-for-abort.js +1 -0
- package/migrations/postgres/{20260119153838_flimsy_thor_girl → 20260121160012_normal_bloodstrike}/migration.sql +32 -20
- package/migrations/postgres/{20260119153838_flimsy_thor_girl → 20260121160012_normal_bloodstrike}/snapshot.json +241 -66
- package/package.json +42 -26
- package/src/action-job.ts +43 -32
- package/src/action-manager.ts +5 -5
- package/src/action.ts +317 -149
- package/src/adapters/adapter.ts +54 -54
- package/src/adapters/postgres/base.ts +266 -86
- package/src/adapters/postgres/schema.default.ts +2 -2
- package/src/adapters/postgres/schema.ts +52 -24
- package/src/adapters/schemas.ts +91 -36
- package/src/client.ts +322 -68
- package/src/errors.ts +141 -30
- package/src/index.ts +2 -0
- package/src/server.ts +39 -37
- package/src/step-manager.ts +254 -91
- package/src/telemetry/index.ts +2 -20
- package/src/telemetry/local-span-exporter.ts +148 -0
- package/dist/telemetry/adapter.d.ts +0 -107
- package/dist/telemetry/adapter.d.ts.map +0 -1
- package/dist/telemetry/adapter.js +0 -134
- package/dist/telemetry/local.d.ts +0 -22
- package/dist/telemetry/local.d.ts.map +0 -1
- package/dist/telemetry/local.js +0 -243
- package/dist/telemetry/noop.d.ts +0 -17
- package/dist/telemetry/noop.d.ts.map +0 -1
- package/dist/telemetry/noop.js +0 -66
- package/dist/telemetry/opentelemetry.d.ts +0 -25
- package/dist/telemetry/opentelemetry.d.ts.map +0 -1
- package/dist/telemetry/opentelemetry.js +0 -312
- package/src/telemetry/adapter.ts +0 -642
- package/src/telemetry/local.ts +0 -429
- package/src/telemetry/noop.ts +0 -141
- package/src/telemetry/opentelemetry.ts +0 -453
package/dist/adapters/adapter.js
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import { EventEmitter } from 'node:events';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { JOB_STATUS_CANCELLED, JOB_STATUS_COMPLETED, JOB_STATUS_FAILED, STEP_STATUS_CANCELLED, STEP_STATUS_COMPLETED, STEP_STATUS_FAILED, } from '../constants.js';
|
|
4
|
-
import { BooleanResultSchema, CancelJobOptionsSchema, CancelJobStepOptionsSchema, CompleteJobOptionsSchema, CompleteJobStepOptionsSchema, CreateJobOptionsSchema, CreateOrRecoverJobStepOptionsSchema, CreateOrRecoverJobStepResultNullableSchema, DelayJobStepOptionsSchema, DeleteJobOptionsSchema, DeleteJobsOptionsSchema,
|
|
4
|
+
import { BooleanResultSchema, CancelJobOptionsSchema, CancelJobStepOptionsSchema, CompleteJobOptionsSchema, CompleteJobStepOptionsSchema, CreateJobOptionsSchema, CreateOrRecoverJobStepOptionsSchema, CreateOrRecoverJobStepResultNullableSchema, DelayJobStepOptionsSchema, DeleteJobOptionsSchema, DeleteJobsOptionsSchema, DeleteSpansOptionsSchema, FailJobOptionsSchema, FailJobStepOptionsSchema, FetchOptionsSchema, GetActionsResultSchema, GetJobStepsOptionsSchema, GetJobStepsResultSchema, GetJobsOptionsSchema, GetJobsResultSchema, GetSpansOptionsSchema, GetSpansResultSchema, InsertSpanOptionsSchema, JobIdResultSchema, JobSchema, JobStatusResultSchema, JobStepSchema, JobStepStatusResultSchema, JobsArrayResultSchema, NumberResultSchema, RecoverJobsOptionsSchema, RetryJobOptionsSchema, TimeTravelJobOptionsSchema, } from './schemas.js';
|
|
5
|
+
// ============================================================================
|
|
6
|
+
// Abstract Adapter Class
|
|
7
|
+
// ============================================================================
|
|
8
|
+
/**
|
|
9
|
+
* Abstract base class for database adapters.
|
|
10
|
+
* All adapters must extend this class and implement its abstract methods.
|
|
11
|
+
*/
|
|
5
12
|
export class Adapter extends EventEmitter {
|
|
6
13
|
#id;
|
|
7
14
|
#started = false;
|
|
@@ -9,6 +16,15 @@ export class Adapter extends EventEmitter {
|
|
|
9
16
|
#starting = null;
|
|
10
17
|
#stopping = null;
|
|
11
18
|
#logger = null;
|
|
19
|
+
// ============================================================================
|
|
20
|
+
// Lifecycle Methods
|
|
21
|
+
// ============================================================================
|
|
22
|
+
/**
|
|
23
|
+
* Start the adapter.
|
|
24
|
+
* Performs any necessary initialization, such as running migrations or setting up listeners.
|
|
25
|
+
*
|
|
26
|
+
* @returns Promise resolving to `true` if started successfully, `false` otherwise
|
|
27
|
+
*/
|
|
12
28
|
async start() {
|
|
13
29
|
try {
|
|
14
30
|
if (!this.#id) {
|
|
@@ -36,6 +52,12 @@ export class Adapter extends EventEmitter {
|
|
|
36
52
|
throw error;
|
|
37
53
|
}
|
|
38
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* Stop the adapter.
|
|
57
|
+
* Performs cleanup, such as closing database connections.
|
|
58
|
+
*
|
|
59
|
+
* @returns Promise resolving to `true` if stopped successfully, `false` otherwise
|
|
60
|
+
*/
|
|
39
61
|
async stop() {
|
|
40
62
|
try {
|
|
41
63
|
if (this.#stopped) {
|
|
@@ -57,6 +79,15 @@ export class Adapter extends EventEmitter {
|
|
|
57
79
|
throw error;
|
|
58
80
|
}
|
|
59
81
|
}
|
|
82
|
+
// ============================================================================
|
|
83
|
+
// Configuration Methods
|
|
84
|
+
// ============================================================================
|
|
85
|
+
/**
|
|
86
|
+
* Set the unique identifier for this adapter instance.
|
|
87
|
+
* Used for multi-process coordination and job ownership.
|
|
88
|
+
*
|
|
89
|
+
* @param id - The unique identifier for this adapter instance
|
|
90
|
+
*/
|
|
60
91
|
setId(id) {
|
|
61
92
|
try {
|
|
62
93
|
this.#id = id;
|
|
@@ -66,6 +97,11 @@ export class Adapter extends EventEmitter {
|
|
|
66
97
|
throw error;
|
|
67
98
|
}
|
|
68
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* Set the logger instance for this adapter.
|
|
102
|
+
*
|
|
103
|
+
* @param logger - The logger instance to use for logging
|
|
104
|
+
*/
|
|
69
105
|
setLogger(logger) {
|
|
70
106
|
try {
|
|
71
107
|
this.#logger = logger;
|
|
@@ -75,12 +111,30 @@ export class Adapter extends EventEmitter {
|
|
|
75
111
|
throw error;
|
|
76
112
|
}
|
|
77
113
|
}
|
|
114
|
+
/**
|
|
115
|
+
* Get the unique identifier for this adapter instance.
|
|
116
|
+
*
|
|
117
|
+
* @returns The unique identifier for this adapter instance
|
|
118
|
+
*/
|
|
78
119
|
get id() {
|
|
79
120
|
return this.#id;
|
|
80
121
|
}
|
|
122
|
+
/**
|
|
123
|
+
* Get the logger instance for this adapter.
|
|
124
|
+
*
|
|
125
|
+
* @returns The logger instance, or `null` if not set
|
|
126
|
+
*/
|
|
81
127
|
get logger() {
|
|
82
128
|
return this.#logger;
|
|
83
129
|
}
|
|
130
|
+
// ============================================================================
|
|
131
|
+
// Job Methods
|
|
132
|
+
// ============================================================================
|
|
133
|
+
/**
|
|
134
|
+
* Create a new job in the database.
|
|
135
|
+
*
|
|
136
|
+
* @returns Promise resolving to the job ID, or `null` if creation failed
|
|
137
|
+
*/
|
|
84
138
|
async createJob(options) {
|
|
85
139
|
try {
|
|
86
140
|
await this.start();
|
|
@@ -97,6 +151,11 @@ export class Adapter extends EventEmitter {
|
|
|
97
151
|
throw error;
|
|
98
152
|
}
|
|
99
153
|
}
|
|
154
|
+
/**
|
|
155
|
+
* Mark a job as completed.
|
|
156
|
+
*
|
|
157
|
+
* @returns Promise resolving to `true` if completed, `false` otherwise
|
|
158
|
+
*/
|
|
100
159
|
async completeJob(options) {
|
|
101
160
|
try {
|
|
102
161
|
await this.start();
|
|
@@ -117,6 +176,11 @@ export class Adapter extends EventEmitter {
|
|
|
117
176
|
throw error;
|
|
118
177
|
}
|
|
119
178
|
}
|
|
179
|
+
/**
|
|
180
|
+
* Mark a job as failed.
|
|
181
|
+
*
|
|
182
|
+
* @returns Promise resolving to `true` if failed, `false` otherwise
|
|
183
|
+
*/
|
|
120
184
|
async failJob(options) {
|
|
121
185
|
try {
|
|
122
186
|
await this.start();
|
|
@@ -137,6 +201,11 @@ export class Adapter extends EventEmitter {
|
|
|
137
201
|
throw error;
|
|
138
202
|
}
|
|
139
203
|
}
|
|
204
|
+
/**
|
|
205
|
+
* Cancel a job.
|
|
206
|
+
*
|
|
207
|
+
* @returns Promise resolving to `true` if cancelled, `false` otherwise
|
|
208
|
+
*/
|
|
140
209
|
async cancelJob(options) {
|
|
141
210
|
try {
|
|
142
211
|
await this.start();
|
|
@@ -157,6 +226,11 @@ export class Adapter extends EventEmitter {
|
|
|
157
226
|
throw error;
|
|
158
227
|
}
|
|
159
228
|
}
|
|
229
|
+
/**
|
|
230
|
+
* Retry a failed job by creating a copy of it with status 'created' and cleared output/error.
|
|
231
|
+
*
|
|
232
|
+
* @returns Promise resolving to the job ID, or `null` if creation failed
|
|
233
|
+
*/
|
|
160
234
|
async retryJob(options) {
|
|
161
235
|
try {
|
|
162
236
|
await this.start();
|
|
@@ -173,6 +247,14 @@ export class Adapter extends EventEmitter {
|
|
|
173
247
|
throw error;
|
|
174
248
|
}
|
|
175
249
|
}
|
|
250
|
+
/**
|
|
251
|
+
* Time travel a job to restart from a specific step.
|
|
252
|
+
* The job must be in completed, failed, or cancelled status.
|
|
253
|
+
* Resets the job and ancestor steps to active status, deletes subsequent steps,
|
|
254
|
+
* and preserves completed parallel siblings.
|
|
255
|
+
*
|
|
256
|
+
* @returns Promise resolving to `true` if time travel succeeded, `false` otherwise
|
|
257
|
+
*/
|
|
176
258
|
async timeTravelJob(options) {
|
|
177
259
|
try {
|
|
178
260
|
await this.start();
|
|
@@ -189,6 +271,12 @@ export class Adapter extends EventEmitter {
|
|
|
189
271
|
throw error;
|
|
190
272
|
}
|
|
191
273
|
}
|
|
274
|
+
/**
|
|
275
|
+
* Delete a job by its ID.
|
|
276
|
+
* Active jobs cannot be deleted.
|
|
277
|
+
*
|
|
278
|
+
* @returns Promise resolving to `true` if deleted, `false` otherwise
|
|
279
|
+
*/
|
|
192
280
|
async deleteJob(options) {
|
|
193
281
|
try {
|
|
194
282
|
await this.start();
|
|
@@ -201,6 +289,12 @@ export class Adapter extends EventEmitter {
|
|
|
201
289
|
throw error;
|
|
202
290
|
}
|
|
203
291
|
}
|
|
292
|
+
/**
|
|
293
|
+
* Delete multiple jobs using the same filters as getJobs.
|
|
294
|
+
* Active jobs cannot be deleted and will be excluded from deletion.
|
|
295
|
+
*
|
|
296
|
+
* @returns Promise resolving to the number of jobs deleted
|
|
297
|
+
*/
|
|
204
298
|
async deleteJobs(options) {
|
|
205
299
|
try {
|
|
206
300
|
await this.start();
|
|
@@ -213,6 +307,11 @@ export class Adapter extends EventEmitter {
|
|
|
213
307
|
throw error;
|
|
214
308
|
}
|
|
215
309
|
}
|
|
310
|
+
/**
|
|
311
|
+
* Fetch jobs from the database respecting concurrency limits per group.
|
|
312
|
+
*
|
|
313
|
+
* @returns Promise resolving to an array of fetched jobs
|
|
314
|
+
*/
|
|
216
315
|
async fetch(options) {
|
|
217
316
|
try {
|
|
218
317
|
await this.start();
|
|
@@ -225,6 +324,11 @@ export class Adapter extends EventEmitter {
|
|
|
225
324
|
throw error;
|
|
226
325
|
}
|
|
227
326
|
}
|
|
327
|
+
/**
|
|
328
|
+
* Recover stuck jobs (jobs that were active but the process that owned them is no longer running).
|
|
329
|
+
*
|
|
330
|
+
* @returns Promise resolving to the number of jobs recovered
|
|
331
|
+
*/
|
|
228
332
|
async recoverJobs(options) {
|
|
229
333
|
try {
|
|
230
334
|
await this.start();
|
|
@@ -237,6 +341,14 @@ export class Adapter extends EventEmitter {
|
|
|
237
341
|
throw error;
|
|
238
342
|
}
|
|
239
343
|
}
|
|
344
|
+
// ============================================================================
|
|
345
|
+
// Step Methods
|
|
346
|
+
// ============================================================================
|
|
347
|
+
/**
|
|
348
|
+
* Create or recover a job step by creating or resetting a step record in the database.
|
|
349
|
+
*
|
|
350
|
+
* @returns Promise resolving to the step, or `null` if creation failed
|
|
351
|
+
*/
|
|
240
352
|
async createOrRecoverJobStep(options) {
|
|
241
353
|
try {
|
|
242
354
|
await this.start();
|
|
@@ -249,6 +361,11 @@ export class Adapter extends EventEmitter {
|
|
|
249
361
|
throw error;
|
|
250
362
|
}
|
|
251
363
|
}
|
|
364
|
+
/**
|
|
365
|
+
* Mark a job step as completed.
|
|
366
|
+
*
|
|
367
|
+
* @returns Promise resolving to `true` if completed, `false` otherwise
|
|
368
|
+
*/
|
|
252
369
|
async completeJobStep(options) {
|
|
253
370
|
try {
|
|
254
371
|
await this.start();
|
|
@@ -256,6 +373,7 @@ export class Adapter extends EventEmitter {
|
|
|
256
373
|
const result = await this._completeJobStep(parsedOptions);
|
|
257
374
|
const success = BooleanResultSchema.parse(result);
|
|
258
375
|
if (success) {
|
|
376
|
+
// Fetch jobId for notification
|
|
259
377
|
const step = await this._getJobStepById(parsedOptions.stepId);
|
|
260
378
|
if (step) {
|
|
261
379
|
await this._notify('step-status-changed', {
|
|
@@ -274,6 +392,11 @@ export class Adapter extends EventEmitter {
|
|
|
274
392
|
throw error;
|
|
275
393
|
}
|
|
276
394
|
}
|
|
395
|
+
/**
|
|
396
|
+
* Mark a job step as failed.
|
|
397
|
+
*
|
|
398
|
+
* @returns Promise resolving to `true` if failed, `false` otherwise
|
|
399
|
+
*/
|
|
277
400
|
async failJobStep(options) {
|
|
278
401
|
try {
|
|
279
402
|
await this.start();
|
|
@@ -281,6 +404,7 @@ export class Adapter extends EventEmitter {
|
|
|
281
404
|
const result = await this._failJobStep(parsedOptions);
|
|
282
405
|
const success = BooleanResultSchema.parse(result);
|
|
283
406
|
if (success) {
|
|
407
|
+
// Fetch jobId for notification
|
|
284
408
|
const step = await this._getJobStepById(parsedOptions.stepId);
|
|
285
409
|
if (step) {
|
|
286
410
|
await this._notify('step-status-changed', {
|
|
@@ -299,6 +423,11 @@ export class Adapter extends EventEmitter {
|
|
|
299
423
|
throw error;
|
|
300
424
|
}
|
|
301
425
|
}
|
|
426
|
+
/**
|
|
427
|
+
* Delay a job step.
|
|
428
|
+
*
|
|
429
|
+
* @returns Promise resolving to `true` if delayed, `false` otherwise
|
|
430
|
+
*/
|
|
302
431
|
async delayJobStep(options) {
|
|
303
432
|
try {
|
|
304
433
|
await this.start();
|
|
@@ -306,6 +435,7 @@ export class Adapter extends EventEmitter {
|
|
|
306
435
|
const result = await this._delayJobStep(parsedOptions);
|
|
307
436
|
const success = BooleanResultSchema.parse(result);
|
|
308
437
|
if (success) {
|
|
438
|
+
// Fetch jobId for notification
|
|
309
439
|
const step = await this._getJobStepById(parsedOptions.stepId);
|
|
310
440
|
if (step) {
|
|
311
441
|
await this._notify('step-delayed', {
|
|
@@ -324,6 +454,11 @@ export class Adapter extends EventEmitter {
|
|
|
324
454
|
throw error;
|
|
325
455
|
}
|
|
326
456
|
}
|
|
457
|
+
/**
|
|
458
|
+
* Cancel a job step.
|
|
459
|
+
*
|
|
460
|
+
* @returns Promise resolving to `true` if cancelled, `false` otherwise
|
|
461
|
+
*/
|
|
327
462
|
async cancelJobStep(options) {
|
|
328
463
|
try {
|
|
329
464
|
await this.start();
|
|
@@ -331,6 +466,7 @@ export class Adapter extends EventEmitter {
|
|
|
331
466
|
const result = await this._cancelJobStep(parsedOptions);
|
|
332
467
|
const success = BooleanResultSchema.parse(result);
|
|
333
468
|
if (success) {
|
|
469
|
+
// Fetch jobId for notification
|
|
334
470
|
const step = await this._getJobStepById(parsedOptions.stepId);
|
|
335
471
|
if (step) {
|
|
336
472
|
await this._notify('step-status-changed', {
|
|
@@ -349,6 +485,15 @@ export class Adapter extends EventEmitter {
|
|
|
349
485
|
throw error;
|
|
350
486
|
}
|
|
351
487
|
}
|
|
488
|
+
// ============================================================================
|
|
489
|
+
// Query Methods
|
|
490
|
+
// ============================================================================
|
|
491
|
+
/**
|
|
492
|
+
* Get a job by its ID. Does not include step information.
|
|
493
|
+
*
|
|
494
|
+
* @param jobId - The ID of the job to retrieve
|
|
495
|
+
* @returns Promise resolving to the job, or `null` if not found
|
|
496
|
+
*/
|
|
352
497
|
async getJobById(jobId) {
|
|
353
498
|
try {
|
|
354
499
|
const parsedJobId = z.string().parse(jobId);
|
|
@@ -363,6 +508,14 @@ export class Adapter extends EventEmitter {
|
|
|
363
508
|
throw error;
|
|
364
509
|
}
|
|
365
510
|
}
|
|
511
|
+
/**
|
|
512
|
+
* Get steps for a job with pagination and fuzzy search.
|
|
513
|
+
* Steps are always ordered by created_at ASC.
|
|
514
|
+
* Steps do not include output data.
|
|
515
|
+
*
|
|
516
|
+
* @param options - Query options including jobId, pagination, and search
|
|
517
|
+
* @returns Promise resolving to steps result with pagination info
|
|
518
|
+
*/
|
|
366
519
|
async getJobSteps(options) {
|
|
367
520
|
try {
|
|
368
521
|
const parsedOptions = GetJobStepsOptionsSchema.parse(options);
|
|
@@ -374,6 +527,13 @@ export class Adapter extends EventEmitter {
|
|
|
374
527
|
throw error;
|
|
375
528
|
}
|
|
376
529
|
}
|
|
530
|
+
/**
|
|
531
|
+
* Get jobs with pagination, filtering, and sorting.
|
|
532
|
+
* Does not include step information or job output.
|
|
533
|
+
*
|
|
534
|
+
* @param options - Query options including pagination, filters, and sort
|
|
535
|
+
* @returns Promise resolving to jobs result with pagination info
|
|
536
|
+
*/
|
|
377
537
|
async getJobs(options) {
|
|
378
538
|
try {
|
|
379
539
|
const parsedOptions = options ? GetJobsOptionsSchema.parse(options) : undefined;
|
|
@@ -385,6 +545,12 @@ export class Adapter extends EventEmitter {
|
|
|
385
545
|
throw error;
|
|
386
546
|
}
|
|
387
547
|
}
|
|
548
|
+
/**
|
|
549
|
+
* Get a step by its ID with all information.
|
|
550
|
+
*
|
|
551
|
+
* @param stepId - The ID of the step to retrieve
|
|
552
|
+
* @returns Promise resolving to the step, or `null` if not found
|
|
553
|
+
*/
|
|
388
554
|
async getJobStepById(stepId) {
|
|
389
555
|
try {
|
|
390
556
|
const parsedStepId = z.string().parse(stepId);
|
|
@@ -399,6 +565,12 @@ export class Adapter extends EventEmitter {
|
|
|
399
565
|
throw error;
|
|
400
566
|
}
|
|
401
567
|
}
|
|
568
|
+
/**
|
|
569
|
+
* Get job status and updatedAt timestamp.
|
|
570
|
+
*
|
|
571
|
+
* @param jobId - The ID of the job
|
|
572
|
+
* @returns Promise resolving to job status result, or `null` if not found
|
|
573
|
+
*/
|
|
402
574
|
async getJobStatus(jobId) {
|
|
403
575
|
try {
|
|
404
576
|
const parsedJobId = z.string().parse(jobId);
|
|
@@ -413,6 +585,12 @@ export class Adapter extends EventEmitter {
|
|
|
413
585
|
throw error;
|
|
414
586
|
}
|
|
415
587
|
}
|
|
588
|
+
/**
|
|
589
|
+
* Get job step status and updatedAt timestamp.
|
|
590
|
+
*
|
|
591
|
+
* @param stepId - The ID of the step
|
|
592
|
+
* @returns Promise resolving to step status result, or `null` if not found
|
|
593
|
+
*/
|
|
416
594
|
async getJobStepStatus(stepId) {
|
|
417
595
|
try {
|
|
418
596
|
const parsedStepId = z.string().parse(stepId);
|
|
@@ -427,6 +605,11 @@ export class Adapter extends EventEmitter {
|
|
|
427
605
|
throw error;
|
|
428
606
|
}
|
|
429
607
|
}
|
|
608
|
+
/**
|
|
609
|
+
* Get action statistics including counts and last job created date.
|
|
610
|
+
*
|
|
611
|
+
* @returns Promise resolving to action statistics
|
|
612
|
+
*/
|
|
430
613
|
async getActions() {
|
|
431
614
|
try {
|
|
432
615
|
const result = await this._getActions();
|
|
@@ -437,45 +620,68 @@ export class Adapter extends EventEmitter {
|
|
|
437
620
|
throw error;
|
|
438
621
|
}
|
|
439
622
|
}
|
|
440
|
-
|
|
623
|
+
// ============================================================================
|
|
624
|
+
// Span Methods (OpenTelemetry)
|
|
625
|
+
// ============================================================================
|
|
626
|
+
/**
|
|
627
|
+
* Insert multiple span records in a single batch operation.
|
|
628
|
+
* Used by LocalSpanExporter to store spans from the OpenTelemetry SDK.
|
|
629
|
+
*
|
|
630
|
+
* @param spans - Array of span data to insert
|
|
631
|
+
* @returns Promise resolving to the number of spans inserted
|
|
632
|
+
*/
|
|
633
|
+
async insertSpans(spans) {
|
|
441
634
|
try {
|
|
442
|
-
if (
|
|
635
|
+
if (spans.length === 0) {
|
|
443
636
|
return 0;
|
|
444
637
|
}
|
|
445
638
|
await this.start();
|
|
446
|
-
const
|
|
447
|
-
const result = await this.
|
|
639
|
+
const parsedSpans = spans.map((s) => InsertSpanOptionsSchema.parse(s));
|
|
640
|
+
const result = await this._insertSpans(parsedSpans);
|
|
448
641
|
return NumberResultSchema.parse(result);
|
|
449
642
|
}
|
|
450
643
|
catch (error) {
|
|
451
|
-
this.#logger?.error(error, 'Error in Adapter.
|
|
644
|
+
this.#logger?.error(error, 'Error in Adapter.insertSpans()');
|
|
452
645
|
throw error;
|
|
453
646
|
}
|
|
454
647
|
}
|
|
455
|
-
|
|
648
|
+
/**
|
|
649
|
+
* Get spans for a job or step.
|
|
650
|
+
*
|
|
651
|
+
* @param options - Query options including jobId/stepId, filters, and sort
|
|
652
|
+
* @returns Promise resolving to spans result
|
|
653
|
+
*/
|
|
654
|
+
async getSpans(options) {
|
|
456
655
|
try {
|
|
457
656
|
await this.start();
|
|
458
|
-
const parsedOptions =
|
|
657
|
+
const parsedOptions = GetSpansOptionsSchema.parse(options);
|
|
658
|
+
// Validate that at least one of jobId or stepId is provided
|
|
459
659
|
if (!parsedOptions.jobId && !parsedOptions.stepId) {
|
|
460
660
|
throw new Error('At least one of jobId or stepId must be provided');
|
|
461
661
|
}
|
|
462
|
-
const result = await this.
|
|
463
|
-
return
|
|
662
|
+
const result = await this._getSpans(parsedOptions);
|
|
663
|
+
return GetSpansResultSchema.parse(result);
|
|
464
664
|
}
|
|
465
665
|
catch (error) {
|
|
466
|
-
this.#logger?.error(error, 'Error in Adapter.
|
|
666
|
+
this.#logger?.error(error, 'Error in Adapter.getSpans()');
|
|
467
667
|
throw error;
|
|
468
668
|
}
|
|
469
669
|
}
|
|
470
|
-
|
|
670
|
+
/**
|
|
671
|
+
* Delete all spans for a job.
|
|
672
|
+
*
|
|
673
|
+
* @param options - Options containing the jobId
|
|
674
|
+
* @returns Promise resolving to the number of spans deleted
|
|
675
|
+
*/
|
|
676
|
+
async deleteSpans(options) {
|
|
471
677
|
try {
|
|
472
678
|
await this.start();
|
|
473
|
-
const parsedOptions =
|
|
474
|
-
const result = await this.
|
|
679
|
+
const parsedOptions = DeleteSpansOptionsSchema.parse(options);
|
|
680
|
+
const result = await this._deleteSpans(parsedOptions);
|
|
475
681
|
return NumberResultSchema.parse(result);
|
|
476
682
|
}
|
|
477
683
|
catch (error) {
|
|
478
|
-
this.#logger?.error(error, 'Error in Adapter.
|
|
684
|
+
this.#logger?.error(error, 'Error in Adapter.deleteSpans()');
|
|
479
685
|
throw error;
|
|
480
686
|
}
|
|
481
687
|
}
|