duron 0.3.0-beta.9 → 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 +88 -23
- 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 +140 -3
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +152 -9
- 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 +403 -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 +33 -29
- 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 +84 -12
- package/src/index.ts +2 -0
- package/src/server.ts +39 -37
- package/src/step-manager.ts +246 -95
- 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/client.d.ts
CHANGED
|
@@ -1,58 +1,305 @@
|
|
|
1
|
+
import { type Span, type Tracer } from '@opentelemetry/api';
|
|
2
|
+
import { type SpanExporter, type SpanProcessor } from '@opentelemetry/sdk-trace-base';
|
|
1
3
|
import pino, { type Logger } from 'pino';
|
|
2
4
|
import * as z from 'zod';
|
|
3
5
|
import type { Action } from './action.js';
|
|
4
|
-
import type { Adapter, GetActionsResult, GetJobStepsOptions, GetJobStepsResult, GetJobsOptions, GetJobsResult,
|
|
6
|
+
import type { Adapter, GetActionsResult, GetJobStepsOptions, GetJobStepsResult, GetJobsOptions, GetJobsResult, GetSpansOptions, GetSpansResult, Job, JobStep } from './adapters/adapter.js';
|
|
5
7
|
import type { JobStatusResult, JobStepStatusResult } from './adapters/schemas.js';
|
|
6
8
|
import { type JobStatus } from './constants.js';
|
|
7
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Extracts the inferred type from an action's input/output schema.
|
|
11
|
+
* Handles the case where the schema might be undefined.
|
|
12
|
+
*/
|
|
8
13
|
type InferActionSchema<T> = T extends z.ZodTypeAny ? z.infer<T> : Record<string, unknown>;
|
|
14
|
+
/**
|
|
15
|
+
* Result returned from waitForJob with untyped input and output.
|
|
16
|
+
*/
|
|
9
17
|
export interface JobResult {
|
|
10
|
-
|
|
18
|
+
id: string;
|
|
11
19
|
actionName: string;
|
|
12
20
|
status: JobStatus;
|
|
13
21
|
groupKey: string;
|
|
22
|
+
description: string | null;
|
|
14
23
|
input: unknown;
|
|
15
24
|
output: unknown;
|
|
16
25
|
error: Job['error'];
|
|
17
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Result returned from runActionAndWait with typed input and output based on the action's Zod schemas.
|
|
29
|
+
*/
|
|
18
30
|
export interface TypedJobResult<TAction extends Action<any, any, any>> {
|
|
19
|
-
|
|
31
|
+
id: string;
|
|
20
32
|
actionName: string;
|
|
21
33
|
status: JobStatus;
|
|
22
34
|
groupKey: string;
|
|
35
|
+
description: string | null;
|
|
23
36
|
input: InferActionSchema<NonNullable<TAction['input']>>;
|
|
24
37
|
output: InferActionSchema<NonNullable<TAction['output']>>;
|
|
25
38
|
error: Job['error'];
|
|
26
39
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
+
/**
|
|
41
|
+
* Telemetry context provided to action and step handlers.
|
|
42
|
+
* Provides access to OpenTelemetry APIs for recording traces and metrics.
|
|
43
|
+
*/
|
|
44
|
+
export interface TelemetryContext {
|
|
45
|
+
/**
|
|
46
|
+
* Get the active OpenTelemetry span for the current job/step.
|
|
47
|
+
* Use standard OTel Span methods: setAttribute, addEvent, recordException, etc.
|
|
48
|
+
*/
|
|
49
|
+
getActiveSpan(): Span;
|
|
50
|
+
/**
|
|
51
|
+
* Get an OpenTelemetry tracer for creating custom spans.
|
|
52
|
+
*
|
|
53
|
+
* @param name - The name of the tracer (typically your service or library name)
|
|
54
|
+
*/
|
|
55
|
+
getTracer(name: string): Tracer;
|
|
56
|
+
/**
|
|
57
|
+
* Record a custom metric as a span event.
|
|
58
|
+
* This is a convenience method that stores metrics as span events
|
|
59
|
+
* which can be queried from the local database when telemetry.local is enabled.
|
|
60
|
+
*
|
|
61
|
+
* @param name - The metric name (e.g., 'tokens.input', 'latency.ms')
|
|
62
|
+
* @param value - The metric value
|
|
63
|
+
* @param attributes - Optional attributes for the metric
|
|
64
|
+
*/
|
|
65
|
+
recordMetric(name: string, value: number, attributes?: Record<string, any>): void;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Options for local telemetry storage.
|
|
69
|
+
*/
|
|
70
|
+
export interface LocalTelemetryOptions {
|
|
71
|
+
/**
|
|
72
|
+
* Delay in milliseconds before flushing spans to the database.
|
|
73
|
+
* Uses BatchSpanProcessor with this delay.
|
|
74
|
+
* @default 5000
|
|
75
|
+
*/
|
|
76
|
+
flushDelayMs?: number;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Telemetry configuration options.
|
|
80
|
+
* Uses OpenTelemetry SDK for tracing.
|
|
81
|
+
*/
|
|
82
|
+
export interface TelemetryOptions {
|
|
83
|
+
/**
|
|
84
|
+
* Enable local span storage in the database.
|
|
85
|
+
* When enabled, spans are stored in the database and can be queried via getSpans().
|
|
86
|
+
* Set to true for default options, or provide LocalTelemetryOptions for custom config.
|
|
87
|
+
*/
|
|
88
|
+
local?: LocalTelemetryOptions | boolean;
|
|
89
|
+
/**
|
|
90
|
+
* Additional span processors to add to the tracer provider.
|
|
91
|
+
* These are merged with the local processor (if enabled).
|
|
92
|
+
*/
|
|
93
|
+
spanProcessors?: SpanProcessor[];
|
|
94
|
+
/**
|
|
95
|
+
* Additional span exporter to use.
|
|
96
|
+
* Will be wrapped in a BatchSpanProcessor and merged with other processors.
|
|
97
|
+
*/
|
|
98
|
+
traceExporter?: SpanExporter;
|
|
99
|
+
/**
|
|
100
|
+
* Service name for OpenTelemetry resource.
|
|
101
|
+
* @default 'duron'
|
|
102
|
+
*/
|
|
103
|
+
serviceName?: string;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Base configuration options for a Duron client instance.
|
|
107
|
+
* These options control job fetching, concurrency, and recovery behavior.
|
|
108
|
+
*/
|
|
109
|
+
export interface BaseOptionsInput {
|
|
110
|
+
/**
|
|
111
|
+
* Unique identifier for this Duron instance.
|
|
112
|
+
* Used for multi-process coordination and job ownership.
|
|
113
|
+
* If not provided, a random UUID will be generated.
|
|
114
|
+
*
|
|
115
|
+
* @example 'worker-1', 'api-server', 'background-processor'
|
|
116
|
+
*/
|
|
117
|
+
id?: string;
|
|
118
|
+
/**
|
|
119
|
+
* Synchronization pattern for fetching jobs from the database.
|
|
120
|
+
*
|
|
121
|
+
* - `'pull'`: Periodically poll the database for new jobs at `pullInterval`
|
|
122
|
+
* - `'push'`: Listen for database notifications when jobs are available (real-time)
|
|
123
|
+
* - `'hybrid'`: Use both pull and push patterns (recommended for reliability)
|
|
124
|
+
* - `false`: Disable automatic job fetching (use `fetch()` manually)
|
|
125
|
+
*
|
|
126
|
+
* @default 'hybrid'
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```typescript
|
|
130
|
+
* // Real-time job processing with fallback polling
|
|
131
|
+
* syncPattern: 'hybrid'
|
|
132
|
+
*
|
|
133
|
+
* // Disable auto-fetching for API-only servers
|
|
134
|
+
* syncPattern: false
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
syncPattern?: 'pull' | 'push' | 'hybrid' | false;
|
|
138
|
+
/**
|
|
139
|
+
* Interval in milliseconds between pull operations when using `'pull'` or `'hybrid'` sync pattern.
|
|
140
|
+
* Lower values mean faster job pickup but more database queries.
|
|
141
|
+
*
|
|
142
|
+
* @default 5000
|
|
143
|
+
*/
|
|
144
|
+
pullInterval?: number;
|
|
145
|
+
/**
|
|
146
|
+
* Maximum number of jobs to fetch in a single batch from the database.
|
|
147
|
+
* Higher values reduce database round-trips but may increase memory usage.
|
|
148
|
+
*
|
|
149
|
+
* @default 10
|
|
150
|
+
*/
|
|
151
|
+
batchSize?: number;
|
|
152
|
+
/**
|
|
153
|
+
* Maximum number of jobs that can run concurrently per action.
|
|
154
|
+
* This controls the concurrency limit for each action's internal queue.
|
|
155
|
+
* Use this to prevent any single action from consuming all resources.
|
|
156
|
+
*
|
|
157
|
+
* @default 100
|
|
158
|
+
*/
|
|
159
|
+
actionConcurrencyLimit?: number;
|
|
160
|
+
/**
|
|
161
|
+
* Maximum number of jobs that can run concurrently per group key.
|
|
162
|
+
* Jobs with the same group key will respect this limit.
|
|
163
|
+
* This is the default value; it can be overridden per-job using `action.groups.concurrency`.
|
|
164
|
+
*
|
|
165
|
+
* @default 10
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* ```typescript
|
|
169
|
+
* // Limit concurrent jobs per user to 2
|
|
170
|
+
* groupConcurrencyLimit: 2
|
|
171
|
+
* ```
|
|
172
|
+
*/
|
|
173
|
+
groupConcurrencyLimit?: number;
|
|
174
|
+
/**
|
|
175
|
+
* Whether to run database migrations on startup.
|
|
176
|
+
* When enabled, Duron will automatically apply pending migrations when the adapter starts.
|
|
177
|
+
* Disable this if you manage migrations separately or use a read-only database connection.
|
|
178
|
+
*
|
|
179
|
+
* @default true
|
|
180
|
+
*/
|
|
181
|
+
migrateOnStart?: boolean;
|
|
182
|
+
/**
|
|
183
|
+
* Whether to recover stuck jobs on startup.
|
|
184
|
+
* Stuck jobs are jobs that were marked as active but the process that owned them
|
|
185
|
+
* is no longer running (e.g., after a crash or restart).
|
|
186
|
+
* These jobs will be reset to 'created' status so they can be picked up again.
|
|
187
|
+
*
|
|
188
|
+
* @default true
|
|
189
|
+
*/
|
|
190
|
+
recoverJobsOnStart?: boolean;
|
|
191
|
+
/**
|
|
192
|
+
* Enable multi-process mode for job recovery.
|
|
193
|
+
* When enabled, Duron will ping other processes to check if they're alive
|
|
194
|
+
* before recovering their jobs. This prevents recovering jobs from processes
|
|
195
|
+
* that are still running but slow to respond.
|
|
196
|
+
*
|
|
197
|
+
* Only enable this if you're running multiple Duron instances sharing the same database.
|
|
198
|
+
*
|
|
199
|
+
* @default false
|
|
200
|
+
*/
|
|
201
|
+
multiProcessMode?: boolean;
|
|
202
|
+
/**
|
|
203
|
+
* Timeout in milliseconds to wait for process ping responses in multi-process mode.
|
|
204
|
+
* Processes that don't respond within this timeout will have their jobs recovered.
|
|
205
|
+
* Increase this value if your processes may be temporarily unresponsive under load.
|
|
206
|
+
*
|
|
207
|
+
* @default 5000
|
|
208
|
+
*/
|
|
209
|
+
processTimeout?: number;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Options for configuring a Duron client instance.
|
|
213
|
+
*
|
|
214
|
+
* @template TActions - Record of action definitions keyed by action name
|
|
215
|
+
* @template TVariables - Type of variables available to actions
|
|
216
|
+
*/
|
|
217
|
+
export interface ClientOptions<TActions extends Record<string, Action<any, any, TVariables>>, TVariables = Record<string, unknown>> extends BaseOptionsInput {
|
|
218
|
+
/**
|
|
219
|
+
* The database adapter to use for storing jobs and steps.
|
|
220
|
+
* Required.
|
|
221
|
+
*/
|
|
40
222
|
database: Adapter;
|
|
223
|
+
/**
|
|
224
|
+
* A record of action definitions, where each key is the action name.
|
|
225
|
+
* Required.
|
|
226
|
+
*/
|
|
41
227
|
actions?: TActions;
|
|
228
|
+
/**
|
|
229
|
+
* Logger instance or log level for logging events and errors.
|
|
230
|
+
* Can be a pino Logger instance or a log level string ('fatal' | 'error' | 'warn' | 'info' | 'debug' | 'trace' | 'silent').
|
|
231
|
+
* If not provided, defaults to 'error' level.
|
|
232
|
+
*/
|
|
42
233
|
logger?: Logger | 'fatal' | 'error' | 'warn' | 'info' | 'debug' | 'trace' | 'silent';
|
|
234
|
+
/**
|
|
235
|
+
* Variables available to all actions via the context.
|
|
236
|
+
* These can be accessed in action handlers using `ctx.var`.
|
|
237
|
+
*/
|
|
43
238
|
variables?: TVariables;
|
|
44
|
-
|
|
239
|
+
/**
|
|
240
|
+
* Optional telemetry configuration for observability.
|
|
241
|
+
* Uses OpenTelemetry SDK for tracing.
|
|
242
|
+
*
|
|
243
|
+
* @example
|
|
244
|
+
* ```typescript
|
|
245
|
+
* // Enable local span storage (stored in the database)
|
|
246
|
+
* telemetry: { local: true }
|
|
247
|
+
*
|
|
248
|
+
* // Enable local storage with custom flush delay
|
|
249
|
+
* telemetry: { local: { flushDelayMs: 10000 } }
|
|
250
|
+
*
|
|
251
|
+
* // Export to external systems (e.g., OTLP)
|
|
252
|
+
* telemetry: { traceExporter: new OTLPTraceExporter() }
|
|
253
|
+
*
|
|
254
|
+
* // Both local storage and external export
|
|
255
|
+
* telemetry: { local: true, traceExporter: new OTLPTraceExporter() }
|
|
256
|
+
* ```
|
|
257
|
+
*/
|
|
258
|
+
telemetry?: TelemetryOptions;
|
|
45
259
|
}
|
|
46
260
|
interface FetchOptions {
|
|
47
261
|
batchSize?: number;
|
|
48
262
|
}
|
|
263
|
+
/**
|
|
264
|
+
* Client is the main entry point for Duron.
|
|
265
|
+
* Manages job execution, action handling, and database operations.
|
|
266
|
+
*
|
|
267
|
+
* @template TActions - Record of action definitions keyed by action name
|
|
268
|
+
* @template TVariables - Type of variables available to actions
|
|
269
|
+
*/
|
|
49
270
|
export declare class Client<TActions extends Record<string, Action<any, any, TVariables>>, TVariables = Record<string, unknown>> {
|
|
50
271
|
#private;
|
|
272
|
+
/**
|
|
273
|
+
* Create a new Duron Client instance.
|
|
274
|
+
*
|
|
275
|
+
* @param options - Configuration options for the client
|
|
276
|
+
*/
|
|
51
277
|
constructor(options: ClientOptions<TActions, TVariables>);
|
|
52
278
|
get logger(): pino.Logger;
|
|
53
|
-
|
|
279
|
+
/**
|
|
280
|
+
* Get the OpenTelemetry tracer for creating custom spans.
|
|
281
|
+
* Always returns a tracer - it's a no-op tracer when no SDK is configured.
|
|
282
|
+
*/
|
|
283
|
+
get tracer(): Tracer;
|
|
284
|
+
/**
|
|
285
|
+
* Get the database adapter instance.
|
|
286
|
+
*/
|
|
54
287
|
get database(): Adapter;
|
|
55
|
-
|
|
288
|
+
/**
|
|
289
|
+
* Check if local span storage is enabled.
|
|
290
|
+
* Returns true if telemetry.local is enabled.
|
|
291
|
+
*/
|
|
292
|
+
get spansEnabled(): boolean;
|
|
293
|
+
/**
|
|
294
|
+
* Force flush any pending telemetry data.
|
|
295
|
+
* Useful in tests or when you need to ensure spans are exported before querying.
|
|
296
|
+
*/
|
|
297
|
+
flushTelemetry(): Promise<void>;
|
|
298
|
+
/**
|
|
299
|
+
* Get the current configuration of this Duron instance.
|
|
300
|
+
*
|
|
301
|
+
* @returns Configuration object including options, actions, and variables
|
|
302
|
+
*/
|
|
56
303
|
getConfig(): {
|
|
57
304
|
actions: TActions | null;
|
|
58
305
|
variables: Record<string, unknown>;
|
|
@@ -67,15 +314,47 @@ export declare class Client<TActions extends Record<string, Action<any, any, TVa
|
|
|
67
314
|
processTimeout: number;
|
|
68
315
|
id?: string | undefined;
|
|
69
316
|
};
|
|
317
|
+
/**
|
|
318
|
+
* Run an action by creating a new job.
|
|
319
|
+
*
|
|
320
|
+
* @param actionName - Name of the action to run
|
|
321
|
+
* @param input - Input data for the action (validated against action's input schema if provided)
|
|
322
|
+
* @returns Promise resolving to the created job ID
|
|
323
|
+
* @throws Error if action is not found or job creation fails
|
|
324
|
+
*/
|
|
70
325
|
runAction<TActionName extends keyof TActions>(actionName: TActionName, input?: NonNullable<TActions[TActionName]['input']> extends z.ZodObject ? z.input<NonNullable<TActions[TActionName]['input']>> : never): Promise<string>;
|
|
326
|
+
/**
|
|
327
|
+
* Run an action and wait for its completion.
|
|
328
|
+
* This is a convenience method that combines `runAction` and `waitForJob`.
|
|
329
|
+
*
|
|
330
|
+
* @param actionName - Name of the action to run
|
|
331
|
+
* @param input - Input data for the action (validated against action's input schema if provided)
|
|
332
|
+
* @param options - Options including abort signal and timeout
|
|
333
|
+
* @returns Promise resolving to the job result with typed input and output
|
|
334
|
+
* @throws Error if action is not found, job creation fails, job is cancelled, or operation is aborted
|
|
335
|
+
*/
|
|
71
336
|
runActionAndWait<TActionName extends keyof TActions>(actionName: TActionName, input?: NonNullable<TActions[TActionName]['input']> extends z.ZodObject ? z.input<NonNullable<TActions[TActionName]['input']>> : never, options?: {
|
|
337
|
+
/**
|
|
338
|
+
* AbortSignal to cancel the operation. If aborted, the job will be cancelled and the promise will reject.
|
|
339
|
+
*/
|
|
72
340
|
signal?: AbortSignal;
|
|
341
|
+
/**
|
|
342
|
+
* Timeout in milliseconds. If the job doesn't complete within this time, the job will be cancelled and the promise will reject.
|
|
343
|
+
*/
|
|
73
344
|
timeout?: number;
|
|
74
345
|
}): Promise<TypedJobResult<TActions[TActionName]>>;
|
|
75
|
-
|
|
346
|
+
/**
|
|
347
|
+
* Fetch and process jobs from the database.
|
|
348
|
+
* Concurrency limits are determined from the latest job created for each groupKey.
|
|
349
|
+
*
|
|
350
|
+
* @param [options.batchSize] - Maximum number of jobs to fetch in this batch (defaults to `batchSize` from client options)
|
|
351
|
+
* @returns Promise resolving to the array of fetched jobs
|
|
352
|
+
*/
|
|
353
|
+
fetch(options?: FetchOptions): Promise<{
|
|
76
354
|
id: string;
|
|
77
355
|
actionName: string;
|
|
78
356
|
groupKey: string;
|
|
357
|
+
description: string | null;
|
|
79
358
|
input: any;
|
|
80
359
|
output: any;
|
|
81
360
|
error: any;
|
|
@@ -87,30 +366,155 @@ export declare class Client<TActions extends Record<string, Action<any, any, TVa
|
|
|
87
366
|
createdAt: Date;
|
|
88
367
|
updatedAt: Date;
|
|
89
368
|
concurrencyLimit: number;
|
|
369
|
+
concurrencyStepLimit: number;
|
|
370
|
+
durationMs: number | null;
|
|
90
371
|
clientId?: string | null | undefined;
|
|
91
372
|
}[]>;
|
|
373
|
+
/**
|
|
374
|
+
* Cancel a job by its ID.
|
|
375
|
+
* If the job is currently being processed, it will be cancelled immediately.
|
|
376
|
+
* Otherwise, it will be cancelled in the database.
|
|
377
|
+
*
|
|
378
|
+
* @param jobId - The ID of the job to cancel
|
|
379
|
+
* @returns Promise resolving to `true` if cancelled, `false` otherwise
|
|
380
|
+
*/
|
|
92
381
|
cancelJob(jobId: string): Promise<boolean>;
|
|
382
|
+
/**
|
|
383
|
+
* Retry a failed job by creating a copy of it with status 'created' and cleared output/error.
|
|
384
|
+
*
|
|
385
|
+
* @param jobId - The ID of the job to retry
|
|
386
|
+
* @returns Promise resolving to the new job ID, or `null` if retry failed
|
|
387
|
+
*/
|
|
93
388
|
retryJob(jobId: string): Promise<string | null>;
|
|
389
|
+
/**
|
|
390
|
+
* Time travel a job to restart from a specific step.
|
|
391
|
+
* The job must be in completed, failed, or cancelled status.
|
|
392
|
+
* Resets the job and ancestor steps to active status, deletes subsequent steps,
|
|
393
|
+
* and preserves completed parallel siblings.
|
|
394
|
+
*
|
|
395
|
+
* @param jobId - The ID of the job to time travel
|
|
396
|
+
* @param stepId - The ID of the step to restart from
|
|
397
|
+
* @returns Promise resolving to `true` if time travel succeeded, `false` otherwise
|
|
398
|
+
*/
|
|
94
399
|
timeTravelJob(jobId: string, stepId: string): Promise<boolean>;
|
|
400
|
+
/**
|
|
401
|
+
* Delete a job by its ID.
|
|
402
|
+
* Active jobs cannot be deleted.
|
|
403
|
+
*
|
|
404
|
+
* @param jobId - The ID of the job to delete
|
|
405
|
+
* @returns Promise resolving to `true` if deleted, `false` otherwise
|
|
406
|
+
*/
|
|
95
407
|
deleteJob(jobId: string): Promise<boolean>;
|
|
408
|
+
/**
|
|
409
|
+
* Delete multiple jobs using the same filters as getJobs.
|
|
410
|
+
* Active jobs cannot be deleted and will be excluded from deletion.
|
|
411
|
+
*
|
|
412
|
+
* @param options - Query options including filters (same as getJobs)
|
|
413
|
+
* @returns Promise resolving to the number of jobs deleted
|
|
414
|
+
*/
|
|
96
415
|
deleteJobs(options?: GetJobsOptions): Promise<number>;
|
|
416
|
+
/**
|
|
417
|
+
* Get a job by its ID. Does not include step information.
|
|
418
|
+
*
|
|
419
|
+
* @param jobId - The ID of the job to retrieve
|
|
420
|
+
* @returns Promise resolving to the job, or `null` if not found
|
|
421
|
+
*/
|
|
97
422
|
getJobById(jobId: string): Promise<Job | null>;
|
|
423
|
+
/**
|
|
424
|
+
* Get steps for a job with pagination and fuzzy search.
|
|
425
|
+
* Steps are always ordered by created_at ASC.
|
|
426
|
+
* Steps do not include output data.
|
|
427
|
+
*
|
|
428
|
+
* @param options - Query options including jobId, pagination, and search
|
|
429
|
+
* @returns Promise resolving to steps result with pagination info
|
|
430
|
+
*/
|
|
98
431
|
getJobSteps(options: GetJobStepsOptions): Promise<GetJobStepsResult>;
|
|
432
|
+
/**
|
|
433
|
+
* Get jobs with pagination, filtering, and sorting.
|
|
434
|
+
* Does not include step information or job output.
|
|
435
|
+
*
|
|
436
|
+
* @param options - Query options including pagination, filters, and sort
|
|
437
|
+
* @returns Promise resolving to jobs result with pagination info
|
|
438
|
+
*/
|
|
99
439
|
getJobs(options?: GetJobsOptions): Promise<GetJobsResult>;
|
|
440
|
+
/**
|
|
441
|
+
* Get a step by its ID with all information.
|
|
442
|
+
*
|
|
443
|
+
* @param stepId - The ID of the step to retrieve
|
|
444
|
+
* @returns Promise resolving to the step, or `null` if not found
|
|
445
|
+
*/
|
|
100
446
|
getJobStepById(stepId: string): Promise<JobStep | null>;
|
|
447
|
+
/**
|
|
448
|
+
* Get job status and updatedAt timestamp.
|
|
449
|
+
*
|
|
450
|
+
* @param jobId - The ID of the job
|
|
451
|
+
* @returns Promise resolving to job status result, or `null` if not found
|
|
452
|
+
*/
|
|
101
453
|
getJobStatus(jobId: string): Promise<JobStatusResult | null>;
|
|
454
|
+
/**
|
|
455
|
+
* Get job step status and updatedAt timestamp.
|
|
456
|
+
*
|
|
457
|
+
* @param stepId - The ID of the step
|
|
458
|
+
* @returns Promise resolving to step status result, or `null` if not found
|
|
459
|
+
*/
|
|
102
460
|
getJobStepStatus(stepId: string): Promise<JobStepStatusResult | null>;
|
|
461
|
+
/**
|
|
462
|
+
* Wait for a job to change status by subscribing to job-status-changed events.
|
|
463
|
+
* When the job status changes, the job result is returned.
|
|
464
|
+
*
|
|
465
|
+
* @param jobId - The ID of the job to wait for
|
|
466
|
+
* @param options - Optional configuration including timeout
|
|
467
|
+
* @returns Promise resolving to the job result when its status changes, or `null` if timeout
|
|
468
|
+
*/
|
|
103
469
|
waitForJob(jobId: string, options?: {
|
|
470
|
+
/**
|
|
471
|
+
* Timeout in milliseconds. If the job status doesn't change within this time, the promise resolves to `null`.
|
|
472
|
+
* Defaults to no timeout (waits indefinitely).
|
|
473
|
+
*/
|
|
104
474
|
timeout?: number;
|
|
475
|
+
/**
|
|
476
|
+
* AbortSignal to cancel waiting. If aborted, the promise resolves to `null`.
|
|
477
|
+
*/
|
|
105
478
|
signal?: AbortSignal;
|
|
106
479
|
}): Promise<JobResult | null>;
|
|
480
|
+
/**
|
|
481
|
+
* Get action statistics including counts and last job created date.
|
|
482
|
+
*
|
|
483
|
+
* @returns Promise resolving to action statistics
|
|
484
|
+
*/
|
|
107
485
|
getActions(): Promise<GetActionsResult>;
|
|
108
|
-
|
|
486
|
+
/**
|
|
487
|
+
* Get spans for a job or step.
|
|
488
|
+
* Only available when telemetry.local is enabled.
|
|
489
|
+
*
|
|
490
|
+
* @param options - Query options including jobId/stepId, filters, and sort
|
|
491
|
+
* @returns Promise resolving to spans result
|
|
492
|
+
* @throws Error if local telemetry is not enabled
|
|
493
|
+
*/
|
|
494
|
+
getSpans(options: GetSpansOptions): Promise<GetSpansResult>;
|
|
495
|
+
/**
|
|
496
|
+
* Get action metadata including input schemas and mock data.
|
|
497
|
+
* This is useful for generating UI forms or mock data.
|
|
498
|
+
*
|
|
499
|
+
* @returns Promise resolving to action metadata
|
|
500
|
+
*/
|
|
109
501
|
getActionsMetadata(): Promise<Array<{
|
|
110
502
|
name: string;
|
|
111
503
|
mockInput: any;
|
|
112
504
|
}>>;
|
|
505
|
+
/**
|
|
506
|
+
* Start the Duron instance.
|
|
507
|
+
* Initializes the database, recovers stuck jobs, and sets up sync patterns.
|
|
508
|
+
*
|
|
509
|
+
* @returns Promise resolving to `true` if started successfully, `false` otherwise
|
|
510
|
+
*/
|
|
113
511
|
start(): Promise<boolean>;
|
|
512
|
+
/**
|
|
513
|
+
* Stop the Duron instance.
|
|
514
|
+
* Stops the pull loop, aborts all running jobs, waits for queues to drain, and stops the database.
|
|
515
|
+
*
|
|
516
|
+
* @returns Promise resolving to `true` if stopped successfully, `false` otherwise
|
|
517
|
+
*/
|
|
114
518
|
stop(): Promise<boolean>;
|
|
115
519
|
}
|
|
116
520
|
export {};
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,EAAE,EAAE,KAAK,MAAM,EAAE,MAAM,MAAM,CAAA;AAExC,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAExB,OAAO,KAAK,EAAE,MAAM,EAA6B,MAAM,aAAa,CAAA;AAEpE,OAAO,KAAK,EACV,OAAO,EACP,gBAAgB,EAChB,kBAAkB,EAClB,iBAAiB,EACjB,cAAc,EACd,aAAa,EACb,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,IAAI,EAAE,KAAK,MAAM,EAAS,MAAM,oBAAoB,CAAA;AAElE,OAAO,EAAsB,KAAK,YAAY,EAAE,KAAK,aAAa,EAAE,MAAM,+BAA+B,CAAA;AAGzG,OAAO,IAAI,EAAE,EAAE,KAAK,MAAM,EAAE,MAAM,MAAM,CAAA;AAExC,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAExB,OAAO,KAAK,EAAE,MAAM,EAA6B,MAAM,aAAa,CAAA;AAEpE,OAAO,KAAK,EACV,OAAO,EACP,gBAAgB,EAChB,kBAAkB,EAClB,iBAAiB,EACjB,cAAc,EACd,aAAa,EACb,eAAe,EACf,cAAc,EACd,GAAG,EACH,OAAO,EACR,MAAM,uBAAuB,CAAA;AAC9B,OAAO,KAAK,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AACjF,OAAO,EAAiE,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAG9G;;;GAGG;AACH,KAAK,iBAAiB,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA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