@igniter-js/jobs 0.1.0 → 0.1.1
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/AGENTS.md +115 -541
- package/CHANGELOG.md +5 -0
- package/README.md +118 -356
- package/dist/adapter-PiDCQWQd.d.mts +529 -0
- package/dist/adapter-PiDCQWQd.d.ts +529 -0
- package/dist/adapters/bullmq.adapter.d.mts +55 -110
- package/dist/adapters/bullmq.adapter.d.ts +55 -110
- package/dist/adapters/bullmq.adapter.js +431 -529
- package/dist/adapters/bullmq.adapter.js.map +1 -1
- package/dist/adapters/bullmq.adapter.mjs +431 -529
- package/dist/adapters/bullmq.adapter.mjs.map +1 -1
- package/dist/adapters/index.d.mts +3 -3
- package/dist/adapters/index.d.ts +3 -3
- package/dist/adapters/index.js +889 -960
- package/dist/adapters/index.js.map +1 -1
- package/dist/adapters/index.mjs +888 -959
- package/dist/adapters/index.mjs.map +1 -1
- package/dist/adapters/memory.adapter.d.mts +52 -98
- package/dist/adapters/memory.adapter.d.ts +52 -98
- package/dist/adapters/memory.adapter.js +471 -473
- package/dist/adapters/memory.adapter.js.map +1 -1
- package/dist/adapters/memory.adapter.mjs +471 -473
- package/dist/adapters/memory.adapter.mjs.map +1 -1
- package/dist/index.d.mts +485 -958
- package/dist/index.d.ts +485 -958
- package/dist/index.js +2053 -917
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2051 -917
- package/dist/index.mjs.map +1 -1
- package/package.json +34 -16
- package/dist/adapter-CcQCatSa.d.mts +0 -1411
- package/dist/adapter-CcQCatSa.d.ts +0 -1411
|
@@ -0,0 +1,529 @@
|
|
|
1
|
+
import { Redis } from 'ioredis';
|
|
2
|
+
import { StandardSchemaV1 } from '@igniter-js/core';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Options for defining a scope used to isolate jobs (single scope supported by spec).
|
|
6
|
+
*/
|
|
7
|
+
interface IgniterJobsScopeOptions {
|
|
8
|
+
/** Whether the scope is mandatory when dispatching jobs. */
|
|
9
|
+
required?: boolean;
|
|
10
|
+
/** Optional human-friendly description. */
|
|
11
|
+
description?: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Represents a single scope entry.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const scope: IgniterJobsScopeEntry<'organization'> = {
|
|
19
|
+
* type: 'organization',
|
|
20
|
+
* id: 'org_123',
|
|
21
|
+
* tags: { plan: 'pro' },
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
interface IgniterJobsScopeEntry<TScope extends string = string> {
|
|
26
|
+
/** Scope type (e.g., organization, workspace). */
|
|
27
|
+
type: TScope;
|
|
28
|
+
/** Scope identifier (string or number). */
|
|
29
|
+
id: string | number;
|
|
30
|
+
/** Optional tags for telemetry or auditing. */
|
|
31
|
+
tags?: Record<string, unknown>;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Registry type for scope definition.
|
|
35
|
+
*/
|
|
36
|
+
type IgniterJobsScopeDefinition<TScope extends string = string> = Record<TScope, IgniterJobsScopeOptions>;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Options for scheduling a job dispatch.
|
|
40
|
+
*/
|
|
41
|
+
interface IgniterJobsScheduleOptions {
|
|
42
|
+
/**
|
|
43
|
+
* Absolute date/time to run the job.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* at: new Date('2025-01-01T10:00:00Z')
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
at?: Date;
|
|
51
|
+
/**
|
|
52
|
+
* Delay in milliseconds before running the job.
|
|
53
|
+
*/
|
|
54
|
+
delay?: number;
|
|
55
|
+
/**
|
|
56
|
+
* Cron expression for repeating jobs.
|
|
57
|
+
*
|
|
58
|
+
* @example "0 2 * * *" // every day at 02:00
|
|
59
|
+
*/
|
|
60
|
+
cron?: string;
|
|
61
|
+
/**
|
|
62
|
+
* Repeat every N milliseconds (mutually exclusive with cron).
|
|
63
|
+
*/
|
|
64
|
+
every?: number;
|
|
65
|
+
/**
|
|
66
|
+
* Maximum number of executions for repeating jobs.
|
|
67
|
+
*/
|
|
68
|
+
maxExecutions?: number;
|
|
69
|
+
/**
|
|
70
|
+
* Timezone used when evaluating cron expressions.
|
|
71
|
+
*/
|
|
72
|
+
tz?: string;
|
|
73
|
+
/**
|
|
74
|
+
* Skip execution on weekends when true.
|
|
75
|
+
*/
|
|
76
|
+
skipWeekends?: boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Restrict execution to business hours (24h format).
|
|
79
|
+
*/
|
|
80
|
+
businessHours?: {
|
|
81
|
+
start: number;
|
|
82
|
+
end: number;
|
|
83
|
+
timezone?: string;
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* Only execute during business hours when true.
|
|
87
|
+
*/
|
|
88
|
+
onlyBusinessHours?: boolean;
|
|
89
|
+
/**
|
|
90
|
+
* Array of day indices (0-6) that are allowed for execution.
|
|
91
|
+
*/
|
|
92
|
+
onlyWeekdays?: number[];
|
|
93
|
+
/**
|
|
94
|
+
* Dates to skip execution (ISO strings or Date objects).
|
|
95
|
+
*/
|
|
96
|
+
skipDates?: Array<string | Date>;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* @fileoverview Schema helpers for @igniter-js/jobs
|
|
101
|
+
* @module @igniter-js/jobs/types/schema
|
|
102
|
+
*/
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* A schema accepted by `@igniter-js/jobs` for input validation.
|
|
106
|
+
*
|
|
107
|
+
* Supports:
|
|
108
|
+
* - Standard Schema v1 (when available)
|
|
109
|
+
* - Zod-like schemas (with `_input`/`_output` and `safeParse`/`parse`)
|
|
110
|
+
*/
|
|
111
|
+
type IgniterJobsSchema = StandardSchemaV1<any, any> | {
|
|
112
|
+
readonly _input?: unknown;
|
|
113
|
+
readonly _output?: unknown;
|
|
114
|
+
parse: (value: unknown) => unknown;
|
|
115
|
+
safeParse?: (value: unknown) => {
|
|
116
|
+
success: true;
|
|
117
|
+
data: unknown;
|
|
118
|
+
} | {
|
|
119
|
+
success: false;
|
|
120
|
+
error: unknown;
|
|
121
|
+
};
|
|
122
|
+
};
|
|
123
|
+
type IgniterJobsInferSchemaInput<TSchema> = TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferInput<TSchema> : TSchema extends {
|
|
124
|
+
_input?: infer TInput;
|
|
125
|
+
} ? TInput : unknown;
|
|
126
|
+
type IgniterJobsInferSchemaOutput<TSchema> = TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TSchema> : TSchema extends {
|
|
127
|
+
_output?: infer TOutput;
|
|
128
|
+
} ? TOutput : unknown;
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Rate limiter configuration applied to job dispatch or worker level.
|
|
132
|
+
*/
|
|
133
|
+
interface IgniterJobsLimiter {
|
|
134
|
+
/** Maximum number of jobs allowed within the duration window. */
|
|
135
|
+
max: number;
|
|
136
|
+
/** Duration of the window in milliseconds. */
|
|
137
|
+
duration: number;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Options controlling job dispatch behavior.
|
|
141
|
+
*/
|
|
142
|
+
interface IgniterJobsInvokeOptions {
|
|
143
|
+
jobId?: string;
|
|
144
|
+
priority?: number;
|
|
145
|
+
delay?: number;
|
|
146
|
+
attempts?: number;
|
|
147
|
+
removeOnComplete?: boolean | number;
|
|
148
|
+
removeOnFail?: boolean | number;
|
|
149
|
+
metadata?: Record<string, unknown>;
|
|
150
|
+
limiter?: IgniterJobsLimiter;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Runtime execution context passed to handlers.
|
|
154
|
+
*/
|
|
155
|
+
interface IgniterJobsExecutionContext<TContext, TInput extends IgniterJobsSchema | unknown = unknown> {
|
|
156
|
+
input: IgniterJobsInferSchemaInput<TInput>;
|
|
157
|
+
context: TContext;
|
|
158
|
+
job: {
|
|
159
|
+
id: string;
|
|
160
|
+
name: string;
|
|
161
|
+
queue: string;
|
|
162
|
+
attemptsMade: number;
|
|
163
|
+
/**
|
|
164
|
+
* Timestamp when the job was created (when available).
|
|
165
|
+
*
|
|
166
|
+
* Some adapters may not provide this information for synthetic executions.
|
|
167
|
+
*/
|
|
168
|
+
createdAt?: Date;
|
|
169
|
+
metadata?: Record<string, unknown>;
|
|
170
|
+
};
|
|
171
|
+
scope?: IgniterJobsScopeEntry;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Hook context shared by lifecycle handlers.
|
|
175
|
+
*/
|
|
176
|
+
interface IgniterJobsHookContext<TContext, TInput extends IgniterJobsSchema | unknown = unknown> extends IgniterJobsExecutionContext<TContext, TInput> {
|
|
177
|
+
startedAt?: Date;
|
|
178
|
+
duration?: number;
|
|
179
|
+
}
|
|
180
|
+
type IgniterJobsStartHook<TContext, TInput extends IgniterJobsSchema | unknown = unknown> = (context: IgniterJobsHookContext<TContext, TInput>) => void | Promise<void>;
|
|
181
|
+
type IgniterJobsSuccessHook<TContext, TInput extends IgniterJobsSchema | unknown = unknown, TResult = unknown> = (context: IgniterJobsHookContext<TContext, TInput> & {
|
|
182
|
+
result: TResult;
|
|
183
|
+
}) => void | Promise<void>;
|
|
184
|
+
type IgniterJobsFailureHook<TContext, TInput extends IgniterJobsSchema | unknown = unknown> = (context: IgniterJobsHookContext<TContext, TInput> & {
|
|
185
|
+
error: Error;
|
|
186
|
+
isFinalAttempt: boolean;
|
|
187
|
+
}) => void | Promise<void>;
|
|
188
|
+
type IgniterJobsProgressHook<TContext, TInput extends IgniterJobsSchema | unknown = unknown> = (context: IgniterJobsHookContext<TContext, TInput> & {
|
|
189
|
+
progress: number;
|
|
190
|
+
message?: string;
|
|
191
|
+
}) => void | Promise<void>;
|
|
192
|
+
/**
|
|
193
|
+
* Definition of a job registered on a queue.
|
|
194
|
+
*/
|
|
195
|
+
interface IgniterJobDefinition<TContext, TInput extends IgniterJobsSchema | unknown = unknown, TResult = unknown> extends IgniterJobsInvokeOptions {
|
|
196
|
+
/** Optional input schema for validation. */
|
|
197
|
+
input?: TInput;
|
|
198
|
+
/** Optional output schema (validation handled externally). */
|
|
199
|
+
output?: IgniterJobsSchema;
|
|
200
|
+
/** Optional queue override (creates child queue in adapters). */
|
|
201
|
+
queue?: string;
|
|
202
|
+
/** Job handler implementation. */
|
|
203
|
+
handler: (context: IgniterJobsExecutionContext<TContext, TInput>) => Promise<TResult> | TResult;
|
|
204
|
+
/** Lifecycle hooks */
|
|
205
|
+
onStart?: IgniterJobsStartHook<TContext, TInput>;
|
|
206
|
+
onProgress?: IgniterJobsProgressHook<TContext, TInput>;
|
|
207
|
+
onSuccess?: IgniterJobsSuccessHook<TContext, TInput, TResult>;
|
|
208
|
+
onFailure?: IgniterJobsFailureHook<TContext, TInput>;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Definition for cron-style recurring tasks.
|
|
212
|
+
*/
|
|
213
|
+
interface IgniterCronDefinition<TContext, TResult = unknown> {
|
|
214
|
+
/** Cron expression (5 or 6 fields depending on engine). */
|
|
215
|
+
cron: string;
|
|
216
|
+
/** Timezone used when evaluating cron expressions. */
|
|
217
|
+
tz?: string;
|
|
218
|
+
/** Maximum number of executions for this schedule (adapter-dependent). */
|
|
219
|
+
maxExecutions?: number;
|
|
220
|
+
/** Skip executions on weekends when true (adapter-dependent). */
|
|
221
|
+
skipWeekends?: boolean;
|
|
222
|
+
/** Restrict executions to business hours when true (adapter-dependent). */
|
|
223
|
+
onlyBusinessHours?: boolean;
|
|
224
|
+
/** Business hours config used when `onlyBusinessHours` is enabled. */
|
|
225
|
+
businessHours?: {
|
|
226
|
+
start: number;
|
|
227
|
+
end: number;
|
|
228
|
+
timezone?: string;
|
|
229
|
+
};
|
|
230
|
+
/** Only execute on these weekdays (0=Sunday..6=Saturday). */
|
|
231
|
+
onlyWeekdays?: number[];
|
|
232
|
+
/** Dates to skip execution (ISO strings or Date objects). */
|
|
233
|
+
skipDates?: Array<string | Date>;
|
|
234
|
+
/** Optional start date for the schedule (adapter-dependent). */
|
|
235
|
+
startDate?: Date;
|
|
236
|
+
/** Optional end date for the schedule (adapter-dependent). */
|
|
237
|
+
endDate?: Date;
|
|
238
|
+
handler: (context: Omit<IgniterJobsExecutionContext<TContext, unknown>, 'input'>) => Promise<TResult> | TResult;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Supported job states for management queries.
|
|
242
|
+
*/
|
|
243
|
+
type IgniterJobStatus = 'waiting' | 'active' | 'completed' | 'failed' | 'delayed' | 'paused';
|
|
244
|
+
/**
|
|
245
|
+
* Result shape for job inspection calls.
|
|
246
|
+
*/
|
|
247
|
+
interface IgniterJobSearchResult<TResult = unknown> {
|
|
248
|
+
id: string;
|
|
249
|
+
name: string;
|
|
250
|
+
queue: string;
|
|
251
|
+
status: IgniterJobStatus;
|
|
252
|
+
input: unknown;
|
|
253
|
+
result?: TResult;
|
|
254
|
+
error?: string;
|
|
255
|
+
progress: number;
|
|
256
|
+
attemptsMade: number;
|
|
257
|
+
priority: number;
|
|
258
|
+
createdAt: Date;
|
|
259
|
+
startedAt?: Date;
|
|
260
|
+
completedAt?: Date;
|
|
261
|
+
metadata?: Record<string, unknown>;
|
|
262
|
+
scope?: IgniterJobsScopeEntry;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Management counts for a queue.
|
|
266
|
+
*/
|
|
267
|
+
interface IgniterJobCounts {
|
|
268
|
+
waiting: number;
|
|
269
|
+
active: number;
|
|
270
|
+
completed: number;
|
|
271
|
+
failed: number;
|
|
272
|
+
delayed: number;
|
|
273
|
+
paused: number;
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Parameters accepted by `.dispatch()`.
|
|
277
|
+
*
|
|
278
|
+
* @example
|
|
279
|
+
* ```typescript
|
|
280
|
+
* await jobs.email.sendWelcome.dispatch({
|
|
281
|
+
* input: { email: 'user@example.com' },
|
|
282
|
+
* delay: 5000,
|
|
283
|
+
* priority: 10,
|
|
284
|
+
* scope: { type: 'organization', id: 'org_1' },
|
|
285
|
+
* })
|
|
286
|
+
* ```
|
|
287
|
+
*/
|
|
288
|
+
type IgniterJobsDispatchParams<TInput = unknown> = {
|
|
289
|
+
input: TInput;
|
|
290
|
+
scope?: IgniterJobsScopeEntry;
|
|
291
|
+
} & IgniterJobsInvokeOptions;
|
|
292
|
+
/**
|
|
293
|
+
* Parameters accepted by `.schedule()`.
|
|
294
|
+
*
|
|
295
|
+
* Scheduling options are applied in addition to base dispatch options.
|
|
296
|
+
*/
|
|
297
|
+
type IgniterJobsScheduleParams<TInput = unknown> = IgniterJobsDispatchParams<TInput> & IgniterJobsScheduleOptions;
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Queue configuration produced by `IgniterQueueBuilder`.
|
|
301
|
+
*/
|
|
302
|
+
interface IgniterJobsQueue<TContext, TJobs extends Record<string, IgniterJobDefinition<TContext, any, any>>, TCron extends Record<string, IgniterCronDefinition<TContext, any>>> {
|
|
303
|
+
name: string;
|
|
304
|
+
jobs: TJobs;
|
|
305
|
+
crons: TCron;
|
|
306
|
+
defaultJobOptions?: Partial<IgniterJobDefinition<TContext, any, any>>;
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Information about a queue used by management APIs.
|
|
310
|
+
*/
|
|
311
|
+
interface IgniterJobsQueueInfo {
|
|
312
|
+
name: string;
|
|
313
|
+
isPaused: boolean;
|
|
314
|
+
jobCounts: IgniterJobCounts;
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Filter for cleaning queues.
|
|
318
|
+
*/
|
|
319
|
+
interface IgniterJobsQueueCleanOptions {
|
|
320
|
+
status: IgniterJobStatus | IgniterJobStatus[];
|
|
321
|
+
olderThan?: number;
|
|
322
|
+
limit?: number;
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Queue-level management operations exposed by adapters.
|
|
326
|
+
*/
|
|
327
|
+
interface IgniterJobsQueueManager {
|
|
328
|
+
list(): Promise<IgniterJobsQueueInfo[]>;
|
|
329
|
+
get(name: string): Promise<IgniterJobsQueueInfo | null>;
|
|
330
|
+
getJobCounts(name: string): Promise<IgniterJobCounts>;
|
|
331
|
+
getJobs(name: string, filter?: {
|
|
332
|
+
status?: IgniterJobStatus[];
|
|
333
|
+
limit?: number;
|
|
334
|
+
offset?: number;
|
|
335
|
+
}): Promise<IgniterJobSearchResult[]>;
|
|
336
|
+
pause(name: string): Promise<void>;
|
|
337
|
+
resume(name: string): Promise<void>;
|
|
338
|
+
isPaused(name: string): Promise<boolean>;
|
|
339
|
+
drain(name: string): Promise<number>;
|
|
340
|
+
clean(name: string, options: IgniterJobsQueueCleanOptions): Promise<number>;
|
|
341
|
+
obliterate(name: string, options?: {
|
|
342
|
+
force?: boolean;
|
|
343
|
+
}): Promise<void>;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* Metrics reported by a worker.
|
|
348
|
+
*/
|
|
349
|
+
interface IgniterJobsWorkerMetrics {
|
|
350
|
+
processed: number;
|
|
351
|
+
failed: number;
|
|
352
|
+
avgDuration: number;
|
|
353
|
+
concurrency: number;
|
|
354
|
+
uptime: number;
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Handlers invoked during worker lifecycle.
|
|
358
|
+
*/
|
|
359
|
+
interface IgniterJobsWorkerHandlers {
|
|
360
|
+
onActive?: (ctx: {
|
|
361
|
+
job: IgniterJobSearchResult;
|
|
362
|
+
}) => void | Promise<void>;
|
|
363
|
+
onSuccess?: (ctx: {
|
|
364
|
+
job: IgniterJobSearchResult;
|
|
365
|
+
result: unknown;
|
|
366
|
+
}) => void | Promise<void>;
|
|
367
|
+
onFailure?: (ctx: {
|
|
368
|
+
job: IgniterJobSearchResult;
|
|
369
|
+
error: Error;
|
|
370
|
+
}) => void | Promise<void>;
|
|
371
|
+
onIdle?: () => void | Promise<void>;
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Worker configuration passed to adapters.
|
|
375
|
+
*/
|
|
376
|
+
interface IgniterJobsWorkerBuilderConfig {
|
|
377
|
+
queues: string[];
|
|
378
|
+
concurrency?: number;
|
|
379
|
+
limiter?: IgniterJobsLimiter;
|
|
380
|
+
handlers?: IgniterJobsWorkerHandlers;
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Handle returned by adapter worker creation.
|
|
384
|
+
*/
|
|
385
|
+
interface IgniterJobsWorkerHandle {
|
|
386
|
+
readonly id: string;
|
|
387
|
+
readonly queues: string[];
|
|
388
|
+
pause(): Promise<void>;
|
|
389
|
+
resume(): Promise<void>;
|
|
390
|
+
close(): Promise<void>;
|
|
391
|
+
isRunning(): boolean;
|
|
392
|
+
isPaused(): boolean;
|
|
393
|
+
isClosed(): boolean;
|
|
394
|
+
getMetrics(): Promise<IgniterJobsWorkerMetrics>;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* Base shape for any jobs event emitted by the package.
|
|
399
|
+
*/
|
|
400
|
+
interface IgniterJobsEvent<TType extends string = string, TPayload = unknown> {
|
|
401
|
+
type: TType;
|
|
402
|
+
data: TPayload;
|
|
403
|
+
timestamp: Date;
|
|
404
|
+
scope?: IgniterJobsScopeEntry;
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* Handler signature for subscribe/listen APIs.
|
|
408
|
+
*/
|
|
409
|
+
type IgniterJobsEventHandler<TEvent extends IgniterJobsEvent = IgniterJobsEvent> = (event: TEvent) => void | Promise<void>;
|
|
410
|
+
/**
|
|
411
|
+
* Telemetry instance expected by the jobs package.
|
|
412
|
+
*
|
|
413
|
+
* This interface mirrors the public API of `IgniterTelemetry` from `@igniter-js/telemetry`.
|
|
414
|
+
* It is intentionally defined here to avoid a hard dependency on the telemetry package,
|
|
415
|
+
* which is an optional peer dependency.
|
|
416
|
+
*
|
|
417
|
+
* The jobs runtime calls `telemetry.emit(eventName, { attributes })` during job lifecycle
|
|
418
|
+
* events (enqueued, started, completed, failed, etc.).
|
|
419
|
+
*
|
|
420
|
+
* @example
|
|
421
|
+
* ```typescript
|
|
422
|
+
* import { IgniterTelemetry } from '@igniter-js/telemetry'
|
|
423
|
+
* import { IgniterJobsTelemetryEvents } from '@igniter-js/jobs'
|
|
424
|
+
*
|
|
425
|
+
* const telemetry = IgniterTelemetry.create()
|
|
426
|
+
* .withService('my-api')
|
|
427
|
+
* .withEnvironment('production')
|
|
428
|
+
* .addEvents(IgniterJobsTelemetryEvents)
|
|
429
|
+
* .build()
|
|
430
|
+
*
|
|
431
|
+
* const jobs = IgniterJobs.create()
|
|
432
|
+
* .withTelemetry(telemetry)
|
|
433
|
+
* // ...
|
|
434
|
+
* .build()
|
|
435
|
+
* ```
|
|
436
|
+
*/
|
|
437
|
+
interface IgniterJobsTelemetry {
|
|
438
|
+
/**
|
|
439
|
+
* Emits a telemetry event with optional attributes.
|
|
440
|
+
*
|
|
441
|
+
* @param name - The event name (e.g., 'igniter.jobs.job.completed')
|
|
442
|
+
* @param input - Optional emit configuration containing attributes, level, etc.
|
|
443
|
+
*/
|
|
444
|
+
emit(name: string, input?: {
|
|
445
|
+
attributes?: Record<string, string | number | boolean | null>;
|
|
446
|
+
level?: string;
|
|
447
|
+
}): void;
|
|
448
|
+
/**
|
|
449
|
+
* The service name configured on the telemetry instance.
|
|
450
|
+
*/
|
|
451
|
+
readonly service: string;
|
|
452
|
+
/**
|
|
453
|
+
* The environment name configured on the telemetry instance.
|
|
454
|
+
*/
|
|
455
|
+
readonly environment: string;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
/**
|
|
459
|
+
* Dispatch parameters forwarded to adapters.
|
|
460
|
+
*/
|
|
461
|
+
type IgniterJobsAdapterDispatchParams = {
|
|
462
|
+
queue: string;
|
|
463
|
+
jobName: string;
|
|
464
|
+
} & IgniterJobsDispatchParams;
|
|
465
|
+
/**
|
|
466
|
+
* Schedule parameters forwarded to adapters.
|
|
467
|
+
*/
|
|
468
|
+
type IgniterJobsAdapterScheduleParams = {
|
|
469
|
+
queue: string;
|
|
470
|
+
jobName: string;
|
|
471
|
+
} & IgniterJobsScheduleParams;
|
|
472
|
+
/**
|
|
473
|
+
* Job log entry returned by management APIs.
|
|
474
|
+
*/
|
|
475
|
+
interface IgniterJobsJobLog {
|
|
476
|
+
timestamp: Date;
|
|
477
|
+
message: string;
|
|
478
|
+
level: 'info' | 'warn' | 'error';
|
|
479
|
+
}
|
|
480
|
+
/**
|
|
481
|
+
* Adapter contract for jobs backends.
|
|
482
|
+
*/
|
|
483
|
+
interface IgniterJobsAdapter {
|
|
484
|
+
readonly client: unknown;
|
|
485
|
+
readonly queues: IgniterJobsQueueManager;
|
|
486
|
+
dispatch(params: IgniterJobsAdapterDispatchParams): Promise<string>;
|
|
487
|
+
schedule(params: IgniterJobsAdapterScheduleParams): Promise<string>;
|
|
488
|
+
getJob(jobId: string, queue?: string): Promise<IgniterJobSearchResult | null>;
|
|
489
|
+
getJobState(jobId: string, queue?: string): Promise<IgniterJobStatus | null>;
|
|
490
|
+
getJobLogs(jobId: string, queue?: string): Promise<IgniterJobsJobLog[]>;
|
|
491
|
+
getJobProgress(jobId: string, queue?: string): Promise<number>;
|
|
492
|
+
retryJob(jobId: string, queue?: string): Promise<void>;
|
|
493
|
+
removeJob(jobId: string, queue?: string): Promise<void>;
|
|
494
|
+
promoteJob(jobId: string, queue?: string): Promise<void>;
|
|
495
|
+
moveJobToFailed(jobId: string, reason: string, queue?: string): Promise<void>;
|
|
496
|
+
retryManyJobs(jobIds: string[], queue?: string): Promise<void>;
|
|
497
|
+
removeManyJobs(jobIds: string[], queue?: string): Promise<void>;
|
|
498
|
+
getQueueInfo(queue: string): Promise<IgniterJobsQueueInfo | null>;
|
|
499
|
+
getQueueJobCounts(queue: string): Promise<IgniterJobCounts>;
|
|
500
|
+
listQueues(): Promise<IgniterJobsQueueInfo[]>;
|
|
501
|
+
pauseQueue(queue: string): Promise<void>;
|
|
502
|
+
resumeQueue(queue: string): Promise<void>;
|
|
503
|
+
drainQueue(queue: string): Promise<number>;
|
|
504
|
+
cleanQueue(queue: string, options: IgniterJobsQueueCleanOptions): Promise<number>;
|
|
505
|
+
obliterateQueue(queue: string, options?: {
|
|
506
|
+
force?: boolean;
|
|
507
|
+
}): Promise<void>;
|
|
508
|
+
retryAllInQueue(queue: string): Promise<number>;
|
|
509
|
+
pauseJobType(queue: string, jobName: string): Promise<void>;
|
|
510
|
+
resumeJobType(queue: string, jobName: string): Promise<void>;
|
|
511
|
+
searchJobs(filter: Record<string, unknown>): Promise<IgniterJobSearchResult[]>;
|
|
512
|
+
searchQueues(filter: Record<string, unknown>): Promise<IgniterJobsQueueInfo[]>;
|
|
513
|
+
searchWorkers(filter: Record<string, unknown>): Promise<IgniterJobsWorkerHandle[]>;
|
|
514
|
+
createWorker(config: IgniterJobsWorkerBuilderConfig): Promise<IgniterJobsWorkerHandle>;
|
|
515
|
+
getWorkers(): Map<string, IgniterJobsWorkerHandle>;
|
|
516
|
+
publishEvent(channel: string, payload: unknown): Promise<void>;
|
|
517
|
+
subscribeEvent(channel: string, handler: IgniterJobsEventHandler): Promise<() => Promise<void>>;
|
|
518
|
+
registerJob(queueName: string, jobName: string, definition: IgniterJobDefinition<any, any, any>): void;
|
|
519
|
+
registerCron(queueName: string, cronName: string, definition: IgniterCronDefinition<any, any>): void;
|
|
520
|
+
shutdown(): Promise<void>;
|
|
521
|
+
}
|
|
522
|
+
/**
|
|
523
|
+
* BullMQ adapter options - primarily Redis connection.
|
|
524
|
+
*/
|
|
525
|
+
interface IgniterJobsBullMQAdapterOptions {
|
|
526
|
+
redis: Redis;
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
export type { IgniterJobsInvokeOptions as A, IgniterJobsExecutionContext as B, IgniterJobsHookContext as C, IgniterJobsStartHook as D, IgniterJobsSuccessHook as E, IgniterJobsFailureHook as F, IgniterJobsProgressHook as G, IgniterJobsScopeEntry as H, IgniterJobsAdapter as I, IgniterJobsScheduleOptions as J, IgniterJobsWorkerMetrics as K, IgniterJobsInferSchemaOutput as L, IgniterJobsQueueManager as a, IgniterJobsBullMQAdapterOptions as b, IgniterJobDefinition as c, IgniterCronDefinition as d, IgniterJobsAdapterDispatchParams as e, IgniterJobsAdapterScheduleParams as f, IgniterJobSearchResult as g, IgniterJobStatus as h, IgniterJobsJobLog as i, IgniterJobsQueueInfo as j, IgniterJobsQueueCleanOptions as k, IgniterJobsWorkerHandle as l, IgniterJobsWorkerBuilderConfig as m, IgniterJobsEventHandler as n, IgniterJobCounts as o, IgniterJobsQueue as p, IgniterJobsScopeDefinition as q, IgniterJobsTelemetry as r, IgniterJobsInferSchemaInput as s, IgniterJobsDispatchParams as t, IgniterJobsScheduleParams as u, IgniterJobsLimiter as v, IgniterJobsWorkerHandlers as w, IgniterJobsScopeOptions as x, IgniterJobsSchema as y, IgniterJobsEvent as z };
|