@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
package/dist/index.d.mts
CHANGED
|
@@ -1,1107 +1,634 @@
|
|
|
1
|
+
import { p as IgniterJobsQueue, I as IgniterJobsAdapter, q as IgniterJobsScopeDefinition, c as IgniterJobDefinition, m as IgniterJobsWorkerBuilderConfig, r as IgniterJobsTelemetry, s as IgniterJobsInferSchemaInput, d as IgniterCronDefinition, g as IgniterJobSearchResult, h as IgniterJobStatus, t as IgniterJobsDispatchParams, u as IgniterJobsScheduleParams, n as IgniterJobsEventHandler, j as IgniterJobsQueueInfo, k as IgniterJobsQueueCleanOptions, v as IgniterJobsLimiter, w as IgniterJobsWorkerHandlers, l as IgniterJobsWorkerHandle, x as IgniterJobsScopeOptions, y as IgniterJobsSchema } from './adapter-PiDCQWQd.mjs';
|
|
2
|
+
export { o as IgniterJobCounts, e as IgniterJobsAdapterDispatchParams, f as IgniterJobsAdapterScheduleParams, b as IgniterJobsBullMQAdapterOptions, z as IgniterJobsEvent, B as IgniterJobsExecutionContext, F as IgniterJobsFailureHook, C as IgniterJobsHookContext, L as IgniterJobsInferSchemaOutput, A as IgniterJobsInvokeOptions, i as IgniterJobsJobLog, G as IgniterJobsProgressHook, a as IgniterJobsQueueManager, J as IgniterJobsScheduleOptions, H as IgniterJobsScopeEntry, D as IgniterJobsStartHook, E as IgniterJobsSuccessHook, K as IgniterJobsWorkerMetrics } from './adapter-PiDCQWQd.mjs';
|
|
1
3
|
import { IgniterLogger, IgniterError } from '@igniter-js/core';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
4
|
+
export { IgniterJobsBullMQAdapter } from './adapters/bullmq.adapter.mjs';
|
|
5
|
+
export { IgniterJobsMemoryAdapter } from './adapters/memory.adapter.mjs';
|
|
6
|
+
import 'ioredis';
|
|
5
7
|
|
|
6
8
|
/**
|
|
7
|
-
*
|
|
8
|
-
* @module @igniter-js/jobs/types/config
|
|
9
|
+
* Configuration used to build the jobs runtime.
|
|
9
10
|
*/
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Full configuration for IgniterJobs.
|
|
13
|
-
*
|
|
14
|
-
* @typeParam TContext - Application context type
|
|
15
|
-
* @typeParam TQueues - Map of queue names to queue configs
|
|
16
|
-
* @typeParam TScope - Scope key (only one allowed)
|
|
17
|
-
* @typeParam TActor - Actor key (only one allowed)
|
|
18
|
-
*/
|
|
19
|
-
interface IgniterJobsConfig<TContext = unknown, TQueues extends Record<string, IgniterQueueConfig<TContext, any, any>> = Record<string, never>, TScope extends string = never, TActor extends string = never> {
|
|
20
|
-
/**
|
|
21
|
-
* Queue adapter (required).
|
|
22
|
-
*/
|
|
11
|
+
interface IgniterJobsConfig<TContext = unknown, TQueues extends Record<string, IgniterJobsQueue<TContext, any, any>> = {}, TScope extends string = never> {
|
|
23
12
|
adapter: IgniterJobsAdapter;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
*/
|
|
28
|
-
context: () => TContext | Promise<TContext>;
|
|
29
|
-
/**
|
|
30
|
-
* Queue configurations.
|
|
31
|
-
*/
|
|
13
|
+
service: string;
|
|
14
|
+
environment: string;
|
|
15
|
+
contextFactory: () => TContext | Promise<TContext>;
|
|
32
16
|
queues: TQueues;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
};
|
|
41
|
-
/**
|
|
42
|
-
* Actor definition (only one allowed).
|
|
43
|
-
* Used for auditing.
|
|
44
|
-
*/
|
|
45
|
-
actor?: TActor extends never ? never : {
|
|
46
|
-
key: TActor;
|
|
47
|
-
options?: IgniterJobActorOptions;
|
|
17
|
+
scopeDefinition?: IgniterJobsScopeDefinition<TScope>;
|
|
18
|
+
queueDefaults?: Partial<IgniterJobDefinition<TContext, any, any>>;
|
|
19
|
+
workerDefaults?: Partial<IgniterJobsWorkerBuilderConfig>;
|
|
20
|
+
autoStartWorker?: {
|
|
21
|
+
queues: (keyof TQueues)[];
|
|
22
|
+
concurrency?: number;
|
|
23
|
+
limiter?: IgniterJobsWorkerBuilderConfig['limiter'];
|
|
48
24
|
};
|
|
49
|
-
/**
|
|
50
|
-
* Telemetry instance for observability.
|
|
51
|
-
*/
|
|
52
|
-
telemetry?: IgniterTelemetry;
|
|
53
|
-
/**
|
|
54
|
-
* Custom logger.
|
|
55
|
-
*/
|
|
56
25
|
logger?: IgniterLogger;
|
|
57
|
-
|
|
58
|
-
* Default job options applied to all jobs.
|
|
59
|
-
*/
|
|
60
|
-
defaults?: {
|
|
61
|
-
/**
|
|
62
|
-
* Default retry configuration.
|
|
63
|
-
*/
|
|
64
|
-
retry?: {
|
|
65
|
-
attempts?: number;
|
|
66
|
-
backoff?: {
|
|
67
|
-
type: 'exponential' | 'fixed' | 'linear';
|
|
68
|
-
delay: number;
|
|
69
|
-
maxDelay?: number;
|
|
70
|
-
};
|
|
71
|
-
};
|
|
72
|
-
/**
|
|
73
|
-
* Default timeout in milliseconds.
|
|
74
|
-
*/
|
|
75
|
-
timeout?: number;
|
|
76
|
-
/**
|
|
77
|
-
* Default remove on complete config.
|
|
78
|
-
*/
|
|
79
|
-
removeOnComplete?: boolean | {
|
|
80
|
-
count?: number;
|
|
81
|
-
age?: number;
|
|
82
|
-
};
|
|
83
|
-
/**
|
|
84
|
-
* Default remove on fail config.
|
|
85
|
-
*/
|
|
86
|
-
removeOnFail?: boolean | {
|
|
87
|
-
count?: number;
|
|
88
|
-
age?: number;
|
|
89
|
-
};
|
|
90
|
-
};
|
|
26
|
+
telemetry?: IgniterJobsTelemetry;
|
|
91
27
|
}
|
|
92
28
|
/**
|
|
93
|
-
* Builder
|
|
94
|
-
*
|
|
95
|
-
* @typeParam TContext - Application context type
|
|
96
|
-
* @typeParam TQueues - Map of queue names to queue configs
|
|
97
|
-
* @typeParam TScope - Scope key
|
|
98
|
-
* @typeParam TActor - Actor key
|
|
29
|
+
* Builder interface placeholder to help fluent APIs type-infer.
|
|
99
30
|
*/
|
|
100
|
-
interface IgniterJobsBuilderState<TContext
|
|
31
|
+
interface IgniterJobsBuilderState<TContext, TQueues extends Record<string, IgniterJobsQueue<TContext, any, any>>, TScope extends string> {
|
|
101
32
|
adapter?: IgniterJobsAdapter;
|
|
102
|
-
|
|
33
|
+
service?: string;
|
|
34
|
+
environment?: string;
|
|
35
|
+
contextFactory?: () => TContext | Promise<TContext>;
|
|
103
36
|
queues: TQueues;
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
37
|
+
scopeDefinition?: IgniterJobsScopeDefinition<TScope>;
|
|
38
|
+
queueDefaults?: Partial<IgniterJobDefinition<TContext, any, any>>;
|
|
39
|
+
workerDefaults?: Partial<IgniterJobsWorkerBuilderConfig>;
|
|
40
|
+
autoStartWorker?: {
|
|
41
|
+
queues: (keyof TQueues)[];
|
|
42
|
+
concurrency?: number;
|
|
43
|
+
limiter?: IgniterJobsWorkerBuilderConfig['limiter'];
|
|
111
44
|
};
|
|
112
|
-
telemetry?: IgniterTelemetry;
|
|
113
|
-
logger?: IgniterLogger;
|
|
114
|
-
defaults?: IgniterJobsConfig<TContext>['defaults'];
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Builder state for IgniterQueue configuration.
|
|
118
|
-
*
|
|
119
|
-
* @typeParam TContext - Application context type
|
|
120
|
-
* @typeParam TJobs - Map of job names to definitions
|
|
121
|
-
* @typeParam TCrons - Map of cron names to definitions
|
|
122
|
-
*/
|
|
123
|
-
interface IgniterQueueBuilderState<TContext = unknown, TJobs extends Record<string, IgniterJobDefinition<TContext, any, any>> = Record<string, never>, TCrons extends Record<string, IgniterCronDefinition<TContext, any>> = Record<string, never>> {
|
|
124
|
-
name: string;
|
|
125
|
-
jobs: TJobs;
|
|
126
|
-
crons: TCrons;
|
|
127
45
|
}
|
|
128
46
|
|
|
129
47
|
/**
|
|
130
|
-
* @fileoverview
|
|
131
|
-
* @module @igniter-js/jobs/types/
|
|
48
|
+
* @fileoverview Runtime surface types for @igniter-js/jobs
|
|
49
|
+
* @module @igniter-js/jobs/types/runtime
|
|
132
50
|
*/
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
51
|
+
|
|
52
|
+
type IgniterJobsInferInput<TInput> = IgniterJobsInferSchemaInput<TInput>;
|
|
53
|
+
type IgniterJobsInferJobInput<TDef> = TDef extends IgniterJobDefinition<any, infer TInput, any> ? IgniterJobsInferInput<TInput> : unknown;
|
|
54
|
+
type IgniterJobsInferCronResult<TDef> = TDef extends IgniterCronDefinition<any, infer TResult> ? TResult : unknown;
|
|
55
|
+
interface IgniterJobsJobInstanceAccessor {
|
|
56
|
+
retrieve(): Promise<IgniterJobSearchResult | null>;
|
|
57
|
+
retry(): Promise<void>;
|
|
58
|
+
remove(): Promise<void>;
|
|
59
|
+
promote(): Promise<void>;
|
|
60
|
+
move(state: 'failed', reason: string): Promise<void>;
|
|
61
|
+
state(): Promise<IgniterJobStatus | null>;
|
|
62
|
+
progress(): Promise<number>;
|
|
63
|
+
logs(): Promise<{
|
|
64
|
+
timestamp: Date;
|
|
65
|
+
message: string;
|
|
66
|
+
level: 'info' | 'warn' | 'error';
|
|
67
|
+
}[]>;
|
|
68
|
+
}
|
|
69
|
+
interface IgniterJobsJobManyAccessor {
|
|
70
|
+
retry(): Promise<void>;
|
|
71
|
+
remove(): Promise<void>;
|
|
72
|
+
}
|
|
73
|
+
interface IgniterJobsJobAccessor<TInput = unknown, TResult = unknown> {
|
|
74
|
+
dispatch(params: IgniterJobsDispatchParams<TInput>): Promise<string>;
|
|
75
|
+
schedule(params: IgniterJobsScheduleParams<TInput>): Promise<string>;
|
|
76
|
+
get(id: string): IgniterJobsJobInstanceAccessor;
|
|
77
|
+
many(ids: string[]): IgniterJobsJobManyAccessor;
|
|
144
78
|
pause(): Promise<void>;
|
|
145
|
-
/**
|
|
146
|
-
* Resume the worker.
|
|
147
|
-
*/
|
|
148
79
|
resume(): Promise<void>;
|
|
149
|
-
|
|
150
|
-
* Close the worker gracefully.
|
|
151
|
-
*/
|
|
152
|
-
close(): Promise<void>;
|
|
153
|
-
/**
|
|
154
|
-
* Check if worker is currently running.
|
|
155
|
-
*/
|
|
156
|
-
isRunning(): boolean;
|
|
157
|
-
/**
|
|
158
|
-
* Check if worker is paused.
|
|
159
|
-
*/
|
|
160
|
-
isPaused(): boolean;
|
|
161
|
-
/**
|
|
162
|
-
* Get worker metrics.
|
|
163
|
-
*/
|
|
164
|
-
getMetrics(): Promise<IgniterWorkerMetrics>;
|
|
80
|
+
subscribe(handler: IgniterJobsEventHandler): Promise<() => Promise<void>>;
|
|
165
81
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
*/
|
|
177
|
-
failed: number;
|
|
178
|
-
/**
|
|
179
|
-
* Total jobs completed successfully.
|
|
180
|
-
*/
|
|
181
|
-
completed: number;
|
|
182
|
-
/**
|
|
183
|
-
* Currently active jobs.
|
|
184
|
-
*/
|
|
185
|
-
active: number;
|
|
186
|
-
/**
|
|
187
|
-
* Worker uptime in milliseconds.
|
|
188
|
-
*/
|
|
189
|
-
uptime: number;
|
|
82
|
+
interface IgniterJobsQueueManagerAccessor {
|
|
83
|
+
retrieve(): Promise<IgniterJobsQueueInfo | null>;
|
|
84
|
+
pause(): Promise<void>;
|
|
85
|
+
resume(): Promise<void>;
|
|
86
|
+
drain(): Promise<number>;
|
|
87
|
+
clean(options: IgniterJobsQueueCleanOptions): Promise<number>;
|
|
88
|
+
obliterate(options?: {
|
|
89
|
+
force?: boolean;
|
|
90
|
+
}): Promise<void>;
|
|
91
|
+
retryAll(): Promise<number>;
|
|
190
92
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
*/
|
|
202
|
-
concurrency: number;
|
|
203
|
-
/**
|
|
204
|
-
* Lock duration in milliseconds.
|
|
205
|
-
*/
|
|
206
|
-
lockDuration?: number;
|
|
207
|
-
/**
|
|
208
|
-
* Rate limiter configuration.
|
|
209
|
-
*/
|
|
210
|
-
limiter?: {
|
|
211
|
-
max: number;
|
|
212
|
-
duration: number;
|
|
93
|
+
type IgniterJobsQueueAccessor<TJobs extends Record<string, IgniterJobDefinition<any, any, any>> = {}> = {
|
|
94
|
+
get(): IgniterJobsQueueManagerAccessor;
|
|
95
|
+
list(filter?: {
|
|
96
|
+
status?: IgniterJobStatus[];
|
|
97
|
+
limit?: number;
|
|
98
|
+
offset?: number;
|
|
99
|
+
}): Promise<IgniterJobSearchResult[]>;
|
|
100
|
+
subscribe(handler: IgniterJobsEventHandler): Promise<() => Promise<void>>;
|
|
101
|
+
readonly jobs: {
|
|
102
|
+
[K in keyof TJobs]: IgniterJobsJobAccessor<IgniterJobsInferJobInput<TJobs[K]>, any>;
|
|
213
103
|
};
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
104
|
+
} & {
|
|
105
|
+
[K in keyof TJobs]: IgniterJobsJobAccessor<IgniterJobsInferJobInput<TJobs[K]>, any>;
|
|
106
|
+
};
|
|
107
|
+
interface IgniterJobsWorkerBuilderAccessor<TQueueNames extends string> {
|
|
108
|
+
create(): IgniterJobsWorkerFluentBuilder<TQueueNames>;
|
|
218
109
|
}
|
|
110
|
+
interface IgniterJobsWorkerFluentBuilder<TQueueNames extends string> {
|
|
111
|
+
addQueue(queue: TQueueNames): IgniterJobsWorkerFluentBuilder<TQueueNames>;
|
|
112
|
+
withConcurrency(concurrency: number): IgniterJobsWorkerFluentBuilder<TQueueNames>;
|
|
113
|
+
withLimiter(limiter: IgniterJobsLimiter): IgniterJobsWorkerFluentBuilder<TQueueNames>;
|
|
114
|
+
onActive(handler: NonNullable<IgniterJobsWorkerHandlers['onActive']>): IgniterJobsWorkerFluentBuilder<TQueueNames>;
|
|
115
|
+
onSuccess(handler: NonNullable<IgniterJobsWorkerHandlers['onSuccess']>): IgniterJobsWorkerFluentBuilder<TQueueNames>;
|
|
116
|
+
onFailure(handler: NonNullable<IgniterJobsWorkerHandlers['onFailure']>): IgniterJobsWorkerFluentBuilder<TQueueNames>;
|
|
117
|
+
onIdle(handler: NonNullable<IgniterJobsWorkerHandlers['onIdle']>): IgniterJobsWorkerFluentBuilder<TQueueNames>;
|
|
118
|
+
start(): Promise<IgniterJobsWorkerHandle>;
|
|
119
|
+
}
|
|
120
|
+
interface IgniterJobsBaseRuntime<TConfig extends IgniterJobsConfig<any, any, any> = IgniterJobsConfig<any, any, any>> {
|
|
121
|
+
readonly config: TConfig;
|
|
122
|
+
subscribe(handler: IgniterJobsEventHandler): Promise<() => Promise<void>>;
|
|
123
|
+
search(target: 'jobs', filter: Record<string, unknown>): Promise<IgniterJobSearchResult[]>;
|
|
124
|
+
search(target: 'queues', filter: Record<string, unknown>): Promise<IgniterJobsQueueInfo[]>;
|
|
125
|
+
search(target: 'workers', filter: Record<string, unknown>): Promise<IgniterJobsWorkerHandle[]>;
|
|
126
|
+
shutdown(): Promise<void>;
|
|
127
|
+
readonly worker: IgniterJobsWorkerBuilderAccessor<keyof TConfig['queues'] & string>;
|
|
128
|
+
scope: TConfig extends IgniterJobsConfig<any, any, infer TScope> ? (TScope extends string ? (type: TScope, id: string | number, tags?: Record<string, unknown>) => IgniterJobsRuntime<TConfig> : never) : never;
|
|
129
|
+
}
|
|
130
|
+
type IgniterJobsRuntime<TConfig extends IgniterJobsConfig<any, any, any> = IgniterJobsConfig<any, any, any>> = IgniterJobsBaseRuntime<TConfig> & {
|
|
131
|
+
[Q in keyof TConfig['queues']]: TConfig['queues'][Q] extends {
|
|
132
|
+
jobs: infer TJobs extends Record<string, IgniterJobDefinition<any, any, any>>;
|
|
133
|
+
} ? IgniterJobsQueueAccessor<TJobs> : IgniterJobsQueueAccessor;
|
|
134
|
+
};
|
|
219
135
|
|
|
220
136
|
/**
|
|
221
|
-
*
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
137
|
+
* Canonical error codes for `@igniter-js/jobs`.
|
|
138
|
+
*/
|
|
139
|
+
declare const IGNITER_JOBS_ERROR_CODES: {
|
|
140
|
+
readonly JOBS_ADAPTER_REQUIRED: "JOBS_ADAPTER_REQUIRED";
|
|
141
|
+
readonly JOBS_SERVICE_REQUIRED: "JOBS_SERVICE_REQUIRED";
|
|
142
|
+
readonly JOBS_CONTEXT_REQUIRED: "JOBS_CONTEXT_REQUIRED";
|
|
143
|
+
readonly JOBS_CONFIGURATION_INVALID: "JOBS_CONFIGURATION_INVALID";
|
|
144
|
+
readonly JOBS_QUEUE_NOT_FOUND: "JOBS_QUEUE_NOT_FOUND";
|
|
145
|
+
readonly JOBS_QUEUE_DUPLICATE: "JOBS_QUEUE_DUPLICATE";
|
|
146
|
+
readonly JOBS_QUEUE_OPERATION_FAILED: "JOBS_QUEUE_OPERATION_FAILED";
|
|
147
|
+
readonly JOBS_INVALID_DEFINITION: "JOBS_INVALID_DEFINITION";
|
|
148
|
+
readonly JOBS_HANDLER_REQUIRED: "JOBS_HANDLER_REQUIRED";
|
|
149
|
+
readonly JOBS_DUPLICATE_JOB: "JOBS_DUPLICATE_JOB";
|
|
150
|
+
readonly JOBS_NOT_FOUND: "JOBS_NOT_FOUND";
|
|
151
|
+
readonly JOBS_NOT_REGISTERED: "JOBS_NOT_REGISTERED";
|
|
152
|
+
readonly JOBS_EXECUTION_FAILED: "JOBS_EXECUTION_FAILED";
|
|
153
|
+
readonly JOBS_TIMEOUT: "JOBS_TIMEOUT";
|
|
154
|
+
readonly JOBS_CONTEXT_FACTORY_FAILED: "JOBS_CONTEXT_FACTORY_FAILED";
|
|
155
|
+
readonly JOBS_VALIDATION_FAILED: "JOBS_VALIDATION_FAILED";
|
|
156
|
+
readonly JOBS_INVALID_INPUT: "JOBS_INVALID_INPUT";
|
|
157
|
+
readonly JOBS_INVALID_CRON: "JOBS_INVALID_CRON";
|
|
158
|
+
readonly JOBS_INVALID_SCHEDULE: "JOBS_INVALID_SCHEDULE";
|
|
159
|
+
readonly JOBS_SCOPE_ALREADY_DEFINED: "JOBS_SCOPE_ALREADY_DEFINED";
|
|
160
|
+
readonly JOBS_WORKER_FAILED: "JOBS_WORKER_FAILED";
|
|
161
|
+
readonly JOBS_ADAPTER_ERROR: "JOBS_ADAPTER_ERROR";
|
|
162
|
+
readonly JOBS_ADAPTER_CONNECTION_FAILED: "JOBS_ADAPTER_CONNECTION_FAILED";
|
|
163
|
+
readonly JOBS_SUBSCRIBE_FAILED: "JOBS_SUBSCRIBE_FAILED";
|
|
164
|
+
};
|
|
165
|
+
type IgniterJobsErrorCode = keyof typeof IGNITER_JOBS_ERROR_CODES;
|
|
166
|
+
interface IgniterJobsErrorOptions {
|
|
167
|
+
/** Error code scoped to Igniter Jobs. */
|
|
168
|
+
code: IgniterJobsErrorCode;
|
|
169
|
+
/** Human-readable message. */
|
|
170
|
+
message: string;
|
|
171
|
+
/** HTTP-like status code hint (default: 500). */
|
|
172
|
+
statusCode?: number;
|
|
173
|
+
/** Optional structured details for debugging and clients. */
|
|
174
|
+
details?: unknown;
|
|
175
|
+
/** Optional metadata for logs and tracing. */
|
|
176
|
+
metadata?: Record<string, unknown>;
|
|
177
|
+
/** Optional causer tag used by some Igniter tooling. */
|
|
178
|
+
causer?: string;
|
|
179
|
+
/** Underlying cause for debugging (optional). */
|
|
180
|
+
cause?: Error;
|
|
181
|
+
/** Optional logger passthrough to align with other Igniter errors. */
|
|
182
|
+
logger?: any;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Typed error class for the Jobs package.
|
|
227
186
|
*
|
|
228
187
|
* @example
|
|
229
188
|
* ```typescript
|
|
230
|
-
*
|
|
231
|
-
*
|
|
232
|
-
*
|
|
233
|
-
*
|
|
234
|
-
* const redis = new Redis()
|
|
235
|
-
*
|
|
236
|
-
* const emailQueue = IgniterQueue.create<AppContext>('email')
|
|
237
|
-
* .addJob('sendWelcome', { ... })
|
|
238
|
-
* .build()
|
|
239
|
-
*
|
|
240
|
-
* const jobs = IgniterJobs.create<AppContext>()
|
|
241
|
-
* .withAdapter(BullMQAdapter.create({ redis }))
|
|
242
|
-
* .withContext(() => ({ db, mailer }))
|
|
243
|
-
* .addQueue(emailQueue)
|
|
244
|
-
* .addScope('organization')
|
|
245
|
-
* .addActor('user')
|
|
246
|
-
* .build()
|
|
189
|
+
* throw new IgniterJobsError({
|
|
190
|
+
* code: 'JOBS_INVALID_INPUT',
|
|
191
|
+
* message: 'Input payload failed validation',
|
|
192
|
+
* })
|
|
247
193
|
* ```
|
|
248
194
|
*/
|
|
195
|
+
declare class IgniterJobsError extends IgniterError {
|
|
196
|
+
constructor(options: IgniterJobsErrorOptions);
|
|
197
|
+
}
|
|
249
198
|
|
|
250
199
|
/**
|
|
251
|
-
*
|
|
200
|
+
* Fluent builder responsible for configuring and constructing an `IgniterJobs` instance.
|
|
252
201
|
*
|
|
253
|
-
*
|
|
254
|
-
*
|
|
255
|
-
*
|
|
256
|
-
* @typeParam TActor - Actor key (only one allowed)
|
|
202
|
+
* The builder follows the immutable pattern used across Igniter packages: each
|
|
203
|
+
* method returns a new builder with refined types. Only a single scope is
|
|
204
|
+
* supported per the current specification (no actor support).
|
|
257
205
|
*/
|
|
258
|
-
declare class IgniterJobsBuilder<TContext
|
|
206
|
+
declare class IgniterJobsBuilder<TContext, TQueues extends Record<string, IgniterJobsQueue<TContext, any, any>> = {}, TScope extends string = never> {
|
|
259
207
|
private readonly state;
|
|
260
208
|
private constructor();
|
|
261
209
|
/**
|
|
262
|
-
*
|
|
263
|
-
*
|
|
264
|
-
* @returns A new IgniterJobsBuilder instance
|
|
265
|
-
*
|
|
266
|
-
* @example
|
|
267
|
-
* ```typescript
|
|
268
|
-
* const jobs = IgniterJobs.create<AppContext>()
|
|
269
|
-
* .withAdapter(...)
|
|
270
|
-
* .build()
|
|
271
|
-
* ```
|
|
210
|
+
* Creates the initial builder with no configuration.
|
|
272
211
|
*/
|
|
273
|
-
static create<TContext
|
|
212
|
+
static create<TContext>(): IgniterJobsBuilder<TContext>;
|
|
274
213
|
/**
|
|
275
|
-
*
|
|
276
|
-
*
|
|
277
|
-
* @param adapter - The queue adapter (e.g., BullMQAdapter)
|
|
278
|
-
* @returns The builder with adapter configured
|
|
279
|
-
*
|
|
280
|
-
* @example
|
|
281
|
-
* ```typescript
|
|
282
|
-
* .withAdapter(BullMQAdapter.create({ redis }))
|
|
283
|
-
* ```
|
|
214
|
+
* Returns a new builder with updated state while preserving generics.
|
|
284
215
|
*/
|
|
285
|
-
|
|
216
|
+
private clone;
|
|
286
217
|
/**
|
|
287
|
-
*
|
|
288
|
-
* This function is called for each job to provide the application context.
|
|
289
|
-
*
|
|
290
|
-
* @param contextFn - Function that returns the application context
|
|
291
|
-
* @returns The builder with context configured
|
|
218
|
+
* Attaches the jobs adapter.
|
|
292
219
|
*
|
|
293
|
-
* @
|
|
294
|
-
* ```typescript
|
|
295
|
-
* .withContext(() => ({
|
|
296
|
-
* db: prisma,
|
|
297
|
-
* mailer: mailerService,
|
|
298
|
-
* cache: redis,
|
|
299
|
-
* }))
|
|
300
|
-
* ```
|
|
220
|
+
* @param adapter - Backend adapter implementation (BullMQ, memory, etc.).
|
|
301
221
|
*/
|
|
302
|
-
|
|
222
|
+
withAdapter(adapter: IgniterJobsAdapter): IgniterJobsBuilder<TContext, TQueues, TScope>;
|
|
303
223
|
/**
|
|
304
|
-
*
|
|
305
|
-
*
|
|
306
|
-
* @param queue - Queue configuration from IgniterQueue.create().build()
|
|
307
|
-
* @returns The builder with the queue added
|
|
308
|
-
*
|
|
309
|
-
* @example
|
|
310
|
-
* ```typescript
|
|
311
|
-
* const emailQueue = IgniterQueue.create<AppContext>('email')
|
|
312
|
-
* .addJob('sendWelcome', { ... })
|
|
313
|
-
* .build()
|
|
224
|
+
* Sets the service identifier for telemetry and metrics.
|
|
314
225
|
*
|
|
315
|
-
*
|
|
316
|
-
* .addQueue(emailQueue)
|
|
317
|
-
* .build()
|
|
318
|
-
* ```
|
|
226
|
+
* @param service - Service name (e.g., "my-api").
|
|
319
227
|
*/
|
|
320
|
-
|
|
321
|
-
[K in TQueueState['name']]: TQueueState;
|
|
322
|
-
}, TScope, TActor>;
|
|
228
|
+
withService(service: string): IgniterJobsBuilder<TContext, TQueues, TScope>;
|
|
323
229
|
/**
|
|
324
|
-
*
|
|
325
|
-
* Scopes are used to isolate jobs by organization, tenant, etc.
|
|
326
|
-
*
|
|
327
|
-
* @param key - Scope key (e.g., 'organization', 'tenant')
|
|
328
|
-
* @param options - Optional scope configuration
|
|
329
|
-
* @returns The builder with scope configured
|
|
330
|
-
*
|
|
331
|
-
* @example
|
|
332
|
-
* ```typescript
|
|
333
|
-
* .addScope('organization', { required: true })
|
|
334
|
-
* ```
|
|
230
|
+
* Sets the environment name (e.g., development, staging, production).
|
|
335
231
|
*/
|
|
336
|
-
|
|
232
|
+
withEnvironment(environment: string): IgniterJobsBuilder<TContext, TQueues, TScope>;
|
|
337
233
|
/**
|
|
338
|
-
*
|
|
339
|
-
* Actors are used to track who initiated jobs.
|
|
340
|
-
*
|
|
341
|
-
* @param key - Actor key (e.g., 'user', 'system')
|
|
342
|
-
* @param options - Optional actor configuration
|
|
343
|
-
* @returns The builder with actor configured
|
|
344
|
-
*
|
|
345
|
-
* @example
|
|
346
|
-
* ```typescript
|
|
347
|
-
* .addActor('user', { description: 'The user who initiated the job' })
|
|
348
|
-
* ```
|
|
234
|
+
* Provides a context factory used when executing jobs.
|
|
349
235
|
*/
|
|
350
|
-
|
|
236
|
+
withContext(factory: () => TContext | Promise<TContext>): IgniterJobsBuilder<TContext, TQueues, TScope>;
|
|
351
237
|
/**
|
|
352
|
-
*
|
|
353
|
-
*
|
|
354
|
-
* @param telemetry - IgniterTelemetry instance
|
|
355
|
-
* @returns The builder with telemetry configured
|
|
356
|
-
*
|
|
357
|
-
* @example
|
|
358
|
-
* ```typescript
|
|
359
|
-
* .withTelemetry(telemetry)
|
|
360
|
-
* ```
|
|
238
|
+
* Adds a scope definition (single scope supported).
|
|
361
239
|
*/
|
|
362
|
-
|
|
240
|
+
addScope<TNewScope extends string>(name: TNewScope, options?: IgniterJobsScopeOptions): IgniterJobsBuilder<TContext, TQueues, TScope | TNewScope>;
|
|
363
241
|
/**
|
|
364
|
-
*
|
|
365
|
-
*
|
|
366
|
-
* @param logger - Logger instance
|
|
367
|
-
* @returns The builder with logger configured
|
|
368
|
-
*
|
|
369
|
-
* @example
|
|
370
|
-
* ```typescript
|
|
371
|
-
* .withLogger(customLogger)
|
|
372
|
-
* ```
|
|
242
|
+
* Registers a queue definition on the builder.
|
|
373
243
|
*/
|
|
374
|
-
|
|
244
|
+
addQueue<TName extends string, TQueue extends IgniterJobsQueue<TContext, any, any>>(queue: TQueue & {
|
|
245
|
+
name: TName;
|
|
246
|
+
}): IgniterJobsBuilder<TContext, TQueues & Record<TName, TQueue>, TScope>;
|
|
375
247
|
/**
|
|
376
|
-
*
|
|
377
|
-
*
|
|
378
|
-
* @param defaults - Default job configuration
|
|
379
|
-
* @returns The builder with defaults configured
|
|
380
|
-
*
|
|
381
|
-
* @example
|
|
382
|
-
* ```typescript
|
|
383
|
-
* .withDefaults({
|
|
384
|
-
* retry: { attempts: 3, backoff: { type: 'exponential', delay: 1000 } },
|
|
385
|
-
* timeout: 30000,
|
|
386
|
-
* removeOnComplete: { count: 1000 },
|
|
387
|
-
* })
|
|
388
|
-
* ```
|
|
248
|
+
* Applies default job options to all queues.
|
|
389
249
|
*/
|
|
390
|
-
|
|
391
|
-
retry?: {
|
|
392
|
-
attempts?: number;
|
|
393
|
-
backoff?: {
|
|
394
|
-
type: 'exponential' | 'fixed' | 'linear';
|
|
395
|
-
delay: number;
|
|
396
|
-
maxDelay?: number;
|
|
397
|
-
};
|
|
398
|
-
};
|
|
399
|
-
timeout?: number;
|
|
400
|
-
removeOnComplete?: boolean | {
|
|
401
|
-
count?: number;
|
|
402
|
-
age?: number;
|
|
403
|
-
};
|
|
404
|
-
removeOnFail?: boolean | {
|
|
405
|
-
count?: number;
|
|
406
|
-
age?: number;
|
|
407
|
-
};
|
|
408
|
-
}): IgniterJobsBuilder<TContext, TQueues, TScope, TActor>;
|
|
250
|
+
withQueueDefaults(defaults: Partial<IgniterJobDefinition<TContext, any, any>>): IgniterJobsBuilder<TContext, TQueues, TScope>;
|
|
409
251
|
/**
|
|
410
|
-
*
|
|
411
|
-
* Validates configuration and returns a fully typed jobs instance.
|
|
412
|
-
*
|
|
413
|
-
* @returns The IgniterJobs instance with proxy for typed access
|
|
414
|
-
*
|
|
415
|
-
* @throws {IgniterJobsError} If adapter is not configured
|
|
416
|
-
* @throws {IgniterJobsError} If context is not configured
|
|
417
|
-
* @throws {IgniterJobsError} If no queues are defined
|
|
418
|
-
*
|
|
419
|
-
* @example
|
|
420
|
-
* ```typescript
|
|
421
|
-
* const jobs = IgniterJobs.create<AppContext>()
|
|
422
|
-
* .withAdapter(adapter)
|
|
423
|
-
* .withContext(() => context)
|
|
424
|
-
* .addQueue(emailQueue)
|
|
425
|
-
* .build()
|
|
426
|
-
*
|
|
427
|
-
* // Now use with full type safety
|
|
428
|
-
* await jobs.email.sendWelcome.dispatch({ userId: '123' })
|
|
429
|
-
* ```
|
|
252
|
+
* Applies default worker options.
|
|
430
253
|
*/
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
list: (options?: {
|
|
453
|
-
status?: string[];
|
|
454
|
-
limit?: number;
|
|
455
|
-
}) => Promise<any[]>;
|
|
456
|
-
get: () => IgniterQueueManagement;
|
|
457
|
-
};
|
|
458
|
-
/**
|
|
459
|
-
* Job proxy type providing dispatch, schedule, and job management.
|
|
460
|
-
*/
|
|
461
|
-
interface IgniterJobProxy<TContext, TInput, TOutput, TScope extends string, TActor extends string> {
|
|
462
|
-
dispatch: IgniterJobDispatch<TInput, TScope, TActor>;
|
|
463
|
-
schedule: IgniterJobSchedule<TInput, TScope, TActor>;
|
|
464
|
-
get: (jobId: string) => IgniterJobManagement;
|
|
465
|
-
many: (jobIds: string[]) => IgniterJobBatchManagement;
|
|
466
|
-
pause: () => Promise<void>;
|
|
467
|
-
resume: () => Promise<void>;
|
|
468
|
-
subscribe: (handler: (event: any) => void | Promise<void>) => Promise<() => Promise<void>>;
|
|
469
|
-
}
|
|
470
|
-
/**
|
|
471
|
-
* Job dispatch function type.
|
|
472
|
-
*/
|
|
473
|
-
type IgniterJobDispatch<TInput, TScope extends string, TActor extends string> = (input: TInput, options?: IgniterJobDispatchOptions<TScope, TActor>) => Promise<string>;
|
|
474
|
-
/**
|
|
475
|
-
* Job dispatch options.
|
|
476
|
-
*/
|
|
477
|
-
interface IgniterJobDispatchOptions<TScope extends string, TActor extends string> {
|
|
478
|
-
jobId?: string;
|
|
479
|
-
delay?: number;
|
|
480
|
-
priority?: number;
|
|
481
|
-
scope?: TScope extends never ? never : {
|
|
482
|
-
id: string;
|
|
483
|
-
tags?: Record<string, string | number | boolean>;
|
|
484
|
-
};
|
|
485
|
-
actor?: TActor extends never ? never : {
|
|
486
|
-
id?: string;
|
|
487
|
-
tags?: Record<string, string | number | boolean>;
|
|
488
|
-
};
|
|
489
|
-
}
|
|
490
|
-
/**
|
|
491
|
-
* Job schedule function type.
|
|
492
|
-
*/
|
|
493
|
-
type IgniterJobSchedule<TInput, TScope extends string, TActor extends string> = (params: {
|
|
494
|
-
input: TInput;
|
|
495
|
-
at?: Date;
|
|
496
|
-
cron?: string;
|
|
497
|
-
every?: number;
|
|
498
|
-
timezone?: string;
|
|
499
|
-
jobId?: string;
|
|
500
|
-
scope?: TScope extends never ? never : {
|
|
501
|
-
id: string;
|
|
502
|
-
tags?: Record<string, string | number | boolean>;
|
|
503
|
-
};
|
|
504
|
-
actor?: TActor extends never ? never : {
|
|
505
|
-
id?: string;
|
|
506
|
-
tags?: Record<string, string | number | boolean>;
|
|
507
|
-
};
|
|
508
|
-
}) => Promise<string>;
|
|
509
|
-
/**
|
|
510
|
-
* Single job management operations.
|
|
511
|
-
*/
|
|
512
|
-
interface IgniterJobManagement {
|
|
513
|
-
retrieve: () => Promise<any>;
|
|
514
|
-
retry: () => Promise<void>;
|
|
515
|
-
remove: () => Promise<void>;
|
|
516
|
-
state: () => Promise<string | null>;
|
|
517
|
-
progress: () => Promise<number>;
|
|
518
|
-
logs: () => Promise<any[]>;
|
|
519
|
-
promote: () => Promise<void>;
|
|
520
|
-
move: (state: 'failed' | 'completed', reason?: string) => Promise<void>;
|
|
521
|
-
}
|
|
522
|
-
/**
|
|
523
|
-
* Batch job management operations.
|
|
524
|
-
*/
|
|
525
|
-
interface IgniterJobBatchManagement {
|
|
526
|
-
retry: () => Promise<void>;
|
|
527
|
-
remove: () => Promise<void>;
|
|
528
|
-
}
|
|
529
|
-
/**
|
|
530
|
-
* Queue management operations.
|
|
531
|
-
*/
|
|
532
|
-
interface IgniterQueueManagement {
|
|
533
|
-
retrieve: () => Promise<any>;
|
|
534
|
-
pause: () => Promise<void>;
|
|
535
|
-
resume: () => Promise<void>;
|
|
536
|
-
drain: () => Promise<number>;
|
|
537
|
-
clean: (options: {
|
|
538
|
-
status: string | string[];
|
|
539
|
-
olderThan?: number;
|
|
540
|
-
limit?: number;
|
|
541
|
-
}) => Promise<number>;
|
|
542
|
-
obliterate: (options?: {
|
|
543
|
-
force?: boolean;
|
|
544
|
-
}) => Promise<void>;
|
|
545
|
-
retryAll: () => Promise<number>;
|
|
546
|
-
}
|
|
547
|
-
/**
|
|
548
|
-
* Global subscribe function.
|
|
549
|
-
*/
|
|
550
|
-
type IgniterJobsGlobalSubscribe = (handler: (event: any) => void | Promise<void>) => Promise<() => Promise<void>>;
|
|
551
|
-
/**
|
|
552
|
-
* Search function.
|
|
553
|
-
*/
|
|
554
|
-
interface IgniterJobsSearch {
|
|
555
|
-
(target: 'queues', filter?: any): Promise<any[]>;
|
|
556
|
-
(target: 'jobs', filter?: any): Promise<any[]>;
|
|
557
|
-
(target: 'workers', filter?: any): Promise<any[]>;
|
|
558
|
-
}
|
|
559
|
-
/**
|
|
560
|
-
* Worker builder interface.
|
|
561
|
-
*/
|
|
562
|
-
interface IgniterJobsWorkerBuilder<TQueues> {
|
|
563
|
-
create: () => IgniterJobsWorkerConfig<TQueues>;
|
|
564
|
-
}
|
|
565
|
-
/**
|
|
566
|
-
* Worker configuration builder.
|
|
567
|
-
*/
|
|
568
|
-
interface IgniterJobsWorkerConfig<TQueues> {
|
|
569
|
-
forQueues: (...queues: (keyof TQueues)[]) => IgniterJobsWorkerConfig<TQueues>;
|
|
570
|
-
withConcurrency: (concurrency: number) => IgniterJobsWorkerConfig<TQueues>;
|
|
571
|
-
withLockDuration: (duration: number) => IgniterJobsWorkerConfig<TQueues>;
|
|
572
|
-
withLimiter: (config: {
|
|
573
|
-
max: number;
|
|
574
|
-
duration: number;
|
|
575
|
-
}) => IgniterJobsWorkerConfig<TQueues>;
|
|
576
|
-
onIdle: (callback: () => void) => IgniterJobsWorkerConfig<TQueues>;
|
|
577
|
-
start: () => Promise<any>;
|
|
254
|
+
withWorkerDefaults(defaults: Partial<IgniterJobsWorkerBuilderConfig>): IgniterJobsBuilder<TContext, TQueues, TScope>;
|
|
255
|
+
/**
|
|
256
|
+
* Configures automatic worker startup.
|
|
257
|
+
*/
|
|
258
|
+
withAutoStartWorker(config: {
|
|
259
|
+
queues: (keyof TQueues)[];
|
|
260
|
+
concurrency?: number;
|
|
261
|
+
limiter?: IgniterJobsLimiter;
|
|
262
|
+
}): IgniterJobsBuilder<TContext, TQueues, TScope>;
|
|
263
|
+
/**
|
|
264
|
+
* Attaches telemetry support.
|
|
265
|
+
*/
|
|
266
|
+
withTelemetry(telemetry: IgniterJobsTelemetry): IgniterJobsBuilder<TContext, TQueues, TScope>;
|
|
267
|
+
/**
|
|
268
|
+
* Attaches a custom logger.
|
|
269
|
+
*/
|
|
270
|
+
withLogger(logger: IgniterLogger): IgniterJobsBuilder<TContext, TQueues, TScope>;
|
|
271
|
+
/**
|
|
272
|
+
* Finalizes the configuration and returns the runtime instance.
|
|
273
|
+
*/
|
|
274
|
+
build(): IgniterJobsRuntime<IgniterJobsConfig<TContext, TQueues, TScope>>;
|
|
578
275
|
}
|
|
276
|
+
|
|
579
277
|
/**
|
|
580
|
-
*
|
|
581
|
-
*
|
|
582
|
-
* @example
|
|
583
|
-
* ```typescript
|
|
584
|
-
* import { IgniterJobs } from '@igniter-js/jobs'
|
|
585
|
-
*
|
|
586
|
-
* const jobs = IgniterJobs.create<AppContext>()
|
|
587
|
-
* .withAdapter(adapter)
|
|
588
|
-
* .withContext(() => context)
|
|
589
|
-
* .addQueue(emailQueue)
|
|
590
|
-
* .build()
|
|
591
|
-
* ```
|
|
278
|
+
* @fileoverview Queue builder for @igniter-js/jobs
|
|
279
|
+
* @module @igniter-js/jobs/builders/igniter-queue
|
|
592
280
|
*/
|
|
593
|
-
declare const IgniterJobs: {
|
|
594
|
-
create: typeof IgniterJobsBuilder.create;
|
|
595
|
-
};
|
|
596
281
|
|
|
597
282
|
/**
|
|
598
|
-
*
|
|
599
|
-
* @module @igniter-js/jobs/builders/igniter-queue
|
|
600
|
-
*
|
|
601
|
-
* @description
|
|
602
|
-
* Provides a fluent builder API for defining queues with jobs and cron jobs.
|
|
603
|
-
* Queues group related jobs together and provide type-safe job definitions.
|
|
283
|
+
* Builder for defining queues, jobs, and cron tasks.
|
|
604
284
|
*
|
|
605
285
|
* @example
|
|
606
286
|
* ```typescript
|
|
607
287
|
* import { IgniterQueue } from '@igniter-js/jobs'
|
|
608
288
|
* import { z } from 'zod'
|
|
609
289
|
*
|
|
610
|
-
* const emailQueue = IgniterQueue.create
|
|
290
|
+
* const emailQueue = IgniterQueue.create('email')
|
|
291
|
+
* .withContext<{ mailer: Mailer }>()
|
|
611
292
|
* .addJob('sendWelcome', {
|
|
612
|
-
* input: z.object({
|
|
613
|
-
*
|
|
614
|
-
*
|
|
615
|
-
* }),
|
|
616
|
-
* retry: { attempts: 3 },
|
|
617
|
-
* handler: async (ctx) => {
|
|
618
|
-
* await ctx.context.mailer.send({
|
|
619
|
-
* to: ctx.input.email,
|
|
620
|
-
* template: 'welcome',
|
|
621
|
-
* })
|
|
293
|
+
* input: z.object({ email: z.string().email() }),
|
|
294
|
+
* handler: async ({ input, context }) => {
|
|
295
|
+
* await context.mailer.send(input)
|
|
622
296
|
* },
|
|
623
297
|
* })
|
|
624
|
-
* .addCron('
|
|
625
|
-
*
|
|
626
|
-
* handler: async (
|
|
627
|
-
* await
|
|
298
|
+
* .addCron('cleanup', {
|
|
299
|
+
* cron: '0 2 * * *',
|
|
300
|
+
* handler: async ({ context }) => {
|
|
301
|
+
* await context.mailer.cleanup()
|
|
628
302
|
* },
|
|
629
303
|
* })
|
|
630
304
|
* .build()
|
|
631
305
|
* ```
|
|
632
306
|
*/
|
|
633
|
-
|
|
634
|
-
/**
|
|
635
|
-
* Builder for creating queue configurations.
|
|
636
|
-
*
|
|
637
|
-
* @typeParam TContext - Application context type
|
|
638
|
-
* @typeParam TJobs - Map of job names to definitions
|
|
639
|
-
* @typeParam TCrons - Map of cron names to definitions
|
|
640
|
-
*/
|
|
641
|
-
declare class IgniterQueueBuilder<TContext = unknown, TJobs extends Record<string, IgniterJobDefinition<TContext, any, any>> = Record<string, never>, TCrons extends Record<string, IgniterCronDefinition<TContext, any>> = Record<string, never>> {
|
|
307
|
+
declare class IgniterQueueBuilder<TContext, TJobs extends Record<string, IgniterJobDefinition<TContext, any, any>> = {}, TCron extends Record<string, IgniterCronDefinition<TContext, any>> = {}, TName extends string = string> {
|
|
642
308
|
private readonly state;
|
|
643
309
|
private constructor();
|
|
644
310
|
/**
|
|
645
|
-
*
|
|
646
|
-
*
|
|
647
|
-
* @param name - Queue name (kebab-case, e.g., 'email', 'payment-processing')
|
|
648
|
-
* @returns A new IgniterQueueBuilder instance
|
|
649
|
-
*
|
|
650
|
-
* @example
|
|
651
|
-
* ```typescript
|
|
652
|
-
* const emailQueue = IgniterQueue.create<AppContext>('email')
|
|
653
|
-
* ```
|
|
311
|
+
* Creates a new queue builder for the given queue name.
|
|
654
312
|
*/
|
|
655
|
-
static create<
|
|
313
|
+
static create<const TName extends string>(name: TName): IgniterQueueBuilder<unknown, {}, {}, TName>;
|
|
656
314
|
/**
|
|
657
|
-
*
|
|
315
|
+
* Re-types this builder with the application context type.
|
|
658
316
|
*
|
|
659
|
-
*
|
|
660
|
-
* @param definition - Job definition with input schema, handler, retry config, etc.
|
|
661
|
-
* @returns The builder with the new job added
|
|
317
|
+
* This is a type-level helper; it does not mutate runtime state.
|
|
662
318
|
*
|
|
663
319
|
* @example
|
|
664
320
|
* ```typescript
|
|
665
|
-
* .
|
|
666
|
-
*
|
|
667
|
-
*
|
|
668
|
-
* email: z.string().email(),
|
|
669
|
-
* }),
|
|
670
|
-
* retry: { attempts: 3, backoff: { type: 'exponential', delay: 1000 } },
|
|
671
|
-
* handler: async (ctx) => {
|
|
672
|
-
* await ctx.context.mailer.send({
|
|
673
|
-
* to: ctx.input.email,
|
|
674
|
-
* template: 'welcome',
|
|
675
|
-
* })
|
|
676
|
-
* },
|
|
677
|
-
* })
|
|
321
|
+
* const queue = IgniterQueue.create('email')
|
|
322
|
+
* .withContext<AppContext>()
|
|
323
|
+
* .addJob('send', { handler: async ({ context }) => context.mailer.send() })
|
|
678
324
|
* ```
|
|
679
325
|
*/
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
}, TCrons>;
|
|
326
|
+
withContext<TNewContext>(this: IgniterQueueBuilder<unknown, {}, {}, TName>): IgniterQueueBuilder<TNewContext, {}, {}, TName>;
|
|
327
|
+
private clone;
|
|
683
328
|
/**
|
|
684
|
-
*
|
|
329
|
+
* Registers a job on the queue.
|
|
685
330
|
*
|
|
686
|
-
* @param
|
|
687
|
-
* @param definition -
|
|
688
|
-
* @returns The builder with the new cron added
|
|
689
|
-
*
|
|
690
|
-
* @example
|
|
691
|
-
* ```typescript
|
|
692
|
-
* .addCron('cleanupExpired', {
|
|
693
|
-
* expression: '0 0 * * *', // Every day at midnight
|
|
694
|
-
* timezone: 'America/New_York',
|
|
695
|
-
* handler: async (ctx) => {
|
|
696
|
-
* await ctx.context.db.cleanup.expiredSessions()
|
|
697
|
-
* },
|
|
698
|
-
* })
|
|
699
|
-
* ```
|
|
331
|
+
* @param jobName - Unique name of the job inside the queue.
|
|
332
|
+
* @param definition - Job definition (handler, schemas, options, hooks).
|
|
700
333
|
*/
|
|
701
|
-
|
|
702
|
-
[K in TName]: IgniterCronDefinition<TContext, TOutput>;
|
|
703
|
-
}>;
|
|
334
|
+
addJob<TJobName extends string, TInput extends IgniterJobsSchema | unknown, TResult = unknown>(jobName: TJobName, definition: IgniterJobDefinition<TContext, TInput, TResult>): IgniterQueueBuilder<TContext, TJobs & Record<TJobName, IgniterJobDefinition<TContext, TInput, TResult>>, TCron, TName>;
|
|
704
335
|
/**
|
|
705
|
-
*
|
|
706
|
-
*
|
|
707
|
-
* @returns The queue configuration ready to be registered with IgniterJobs
|
|
336
|
+
* Registers a cron task on the queue.
|
|
708
337
|
*
|
|
709
|
-
* @
|
|
710
|
-
*
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
*
|
|
338
|
+
* @param cronName - Unique name of the cron task inside the queue.
|
|
339
|
+
* @param definition - Cron definition (cron string, tz, handler, options).
|
|
340
|
+
*/
|
|
341
|
+
addCron<TCronName extends string, TResult = unknown>(cronName: TCronName, definition: IgniterCronDefinition<TContext, TResult>): IgniterQueueBuilder<TContext, TJobs, TCron & Record<TCronName, IgniterCronDefinition<TContext, TResult>>, TName>;
|
|
342
|
+
/**
|
|
343
|
+
* Finalizes the queue definition.
|
|
715
344
|
*/
|
|
716
|
-
build():
|
|
345
|
+
build(): IgniterJobsQueue<TContext, TJobs, TCron> & {
|
|
346
|
+
name: TName;
|
|
347
|
+
};
|
|
717
348
|
}
|
|
718
|
-
/**
|
|
719
|
-
* Convenience alias for IgniterQueueBuilder.create().
|
|
720
|
-
* Use this to create queue configurations with a fluent API.
|
|
721
|
-
*
|
|
722
|
-
* @example
|
|
723
|
-
* ```typescript
|
|
724
|
-
* import { IgniterQueue } from '@igniter-js/jobs'
|
|
725
|
-
*
|
|
726
|
-
* const emailQueue = IgniterQueue.create<AppContext>('email')
|
|
727
|
-
* .addJob('sendWelcome', { ... })
|
|
728
|
-
* .build()
|
|
729
|
-
* ```
|
|
730
|
-
*/
|
|
731
|
-
declare const IgniterQueue: {
|
|
732
|
-
create: typeof IgniterQueueBuilder.create;
|
|
733
|
-
};
|
|
734
349
|
|
|
735
350
|
/**
|
|
736
|
-
* @fileoverview
|
|
351
|
+
* @fileoverview Worker builder for @igniter-js/jobs
|
|
737
352
|
* @module @igniter-js/jobs/builders/igniter-worker
|
|
738
353
|
*/
|
|
739
354
|
|
|
355
|
+
type IgniterJobsWorkerBuilderState<TAllowedQueues extends string> = {
|
|
356
|
+
queues: TAllowedQueues[];
|
|
357
|
+
concurrency?: number;
|
|
358
|
+
limiter?: IgniterJobsLimiter;
|
|
359
|
+
handlers: IgniterJobsWorkerHandlers;
|
|
360
|
+
};
|
|
740
361
|
/**
|
|
741
|
-
*
|
|
362
|
+
* Fluent builder for creating workers tied to registered queues.
|
|
742
363
|
*
|
|
743
|
-
*
|
|
744
|
-
*
|
|
745
|
-
* const worker = await jobs.worker
|
|
746
|
-
* .create()
|
|
747
|
-
* .forQueues('email', 'payment')
|
|
748
|
-
* .withConcurrency(10)
|
|
749
|
-
* .withLimiter({ max: 100, duration: 60000 })
|
|
750
|
-
* .start()
|
|
751
|
-
* ```
|
|
364
|
+
* Instances of this builder are created by `jobs.worker.create()` so it can be
|
|
365
|
+
* automatically scoped to registered queue names.
|
|
752
366
|
*/
|
|
753
|
-
declare class IgniterWorkerBuilder {
|
|
754
|
-
private
|
|
755
|
-
private
|
|
756
|
-
private
|
|
757
|
-
|
|
758
|
-
|
|
367
|
+
declare class IgniterWorkerBuilder<TAllowedQueues extends string> {
|
|
368
|
+
private readonly adapter;
|
|
369
|
+
private readonly allowedQueues;
|
|
370
|
+
private readonly state;
|
|
371
|
+
constructor(params: {
|
|
372
|
+
adapter: IgniterJobsAdapter;
|
|
373
|
+
allowedQueues: readonly TAllowedQueues[];
|
|
374
|
+
state?: Partial<IgniterJobsWorkerBuilderState<TAllowedQueues>>;
|
|
375
|
+
});
|
|
376
|
+
private clone;
|
|
759
377
|
/**
|
|
760
|
-
*
|
|
761
|
-
* If not called, worker processes all queues.
|
|
762
|
-
*
|
|
763
|
-
* @param queues - Queue names to process
|
|
764
|
-
* @returns The builder for chaining
|
|
378
|
+
* Adds a queue to the worker.
|
|
765
379
|
*
|
|
766
|
-
* @
|
|
767
|
-
* ```typescript
|
|
768
|
-
* .forQueues('email', 'payment')
|
|
769
|
-
* ```
|
|
380
|
+
* @param queue - Queue name registered on the jobs instance.
|
|
770
381
|
*/
|
|
771
|
-
|
|
382
|
+
addQueue(queue: TAllowedQueues): IgniterWorkerBuilder<TAllowedQueues>;
|
|
772
383
|
/**
|
|
773
|
-
*
|
|
774
|
-
*
|
|
775
|
-
* @param concurrency - Number of parallel jobs
|
|
776
|
-
* @returns The builder for chaining
|
|
777
|
-
*
|
|
778
|
-
* @example
|
|
779
|
-
* ```typescript
|
|
780
|
-
* .withConcurrency(10)
|
|
781
|
-
* ```
|
|
384
|
+
* Sets the worker concurrency.
|
|
782
385
|
*/
|
|
783
|
-
withConcurrency(concurrency: number):
|
|
386
|
+
withConcurrency(concurrency: number): IgniterWorkerBuilder<TAllowedQueues>;
|
|
784
387
|
/**
|
|
785
|
-
*
|
|
786
|
-
* Jobs are locked for this duration while being processed.
|
|
787
|
-
*
|
|
788
|
-
* @param duration - Lock duration in milliseconds
|
|
789
|
-
* @returns The builder for chaining
|
|
790
|
-
*
|
|
791
|
-
* @example
|
|
792
|
-
* ```typescript
|
|
793
|
-
* .withLockDuration(30000) // 30 seconds
|
|
794
|
-
* ```
|
|
388
|
+
* Sets a worker-level rate limiter.
|
|
795
389
|
*/
|
|
796
|
-
|
|
390
|
+
withLimiter(limiter: IgniterJobsLimiter): IgniterWorkerBuilder<TAllowedQueues>;
|
|
391
|
+
onActive(handler: NonNullable<IgniterJobsWorkerHandlers['onActive']>): IgniterWorkerBuilder<TAllowedQueues>;
|
|
392
|
+
onSuccess(handler: NonNullable<IgniterJobsWorkerHandlers['onSuccess']>): IgniterWorkerBuilder<TAllowedQueues>;
|
|
393
|
+
onFailure(handler: NonNullable<IgniterJobsWorkerHandlers['onFailure']>): IgniterWorkerBuilder<TAllowedQueues>;
|
|
394
|
+
onIdle(handler: NonNullable<IgniterJobsWorkerHandlers['onIdle']>): IgniterWorkerBuilder<TAllowedQueues>;
|
|
797
395
|
/**
|
|
798
|
-
*
|
|
799
|
-
*
|
|
800
|
-
* @param config - Rate limiter configuration
|
|
801
|
-
* @returns The builder for chaining
|
|
396
|
+
* Builds and starts the worker.
|
|
802
397
|
*
|
|
803
|
-
*
|
|
804
|
-
* ```typescript
|
|
805
|
-
* .withLimiter({ max: 100, duration: 60000 }) // 100 jobs per minute
|
|
806
|
-
* ```
|
|
398
|
+
* If no queues are added explicitly, the adapter should interpret it as "all queues".
|
|
807
399
|
*/
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
400
|
+
start(): Promise<IgniterJobsWorkerHandle>;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* @fileoverview Core runtime factory for @igniter-js/jobs
|
|
405
|
+
* @module @igniter-js/jobs/core/igniter-jobs
|
|
406
|
+
*/
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* Runtime wrapper produced by `IgniterJobsBuilder`.
|
|
410
|
+
*
|
|
411
|
+
* The concrete implementation will expose queue/job proxies, management APIs,
|
|
412
|
+
* worker builder access, and shutdown handling.
|
|
413
|
+
*/
|
|
414
|
+
declare class IgniterJobs {
|
|
812
415
|
/**
|
|
813
|
-
*
|
|
814
|
-
*
|
|
815
|
-
* @param callback - Idle callback
|
|
816
|
-
* @returns The builder for chaining
|
|
416
|
+
* Starts the fluent builder API for jobs.
|
|
817
417
|
*
|
|
818
418
|
* @example
|
|
819
419
|
* ```typescript
|
|
820
|
-
*
|
|
420
|
+
* const jobs = IgniterJobs.create<AppContext>()
|
|
421
|
+
* .withAdapter(IgniterJobsMemoryAdapter.create())
|
|
422
|
+
* .withService('my-api')
|
|
423
|
+
* .withEnvironment('test')
|
|
424
|
+
* .withContext(async () => ({ db }))
|
|
425
|
+
* .addQueue(emailQueue)
|
|
426
|
+
* .build()
|
|
821
427
|
* ```
|
|
822
428
|
*/
|
|
823
|
-
|
|
429
|
+
static create<TContext>(): IgniterJobsBuilder<TContext, {}, never>;
|
|
824
430
|
/**
|
|
825
|
-
*
|
|
826
|
-
*
|
|
827
|
-
* @returns Worker handle for management
|
|
828
|
-
*
|
|
829
|
-
* @example
|
|
830
|
-
* ```typescript
|
|
831
|
-
* const worker = await jobs.worker
|
|
832
|
-
* .create()
|
|
833
|
-
* .forQueues('email')
|
|
834
|
-
* .start()
|
|
835
|
-
*
|
|
836
|
-
* // Later
|
|
837
|
-
* await worker.pause()
|
|
838
|
-
* await worker.close()
|
|
839
|
-
* ```
|
|
431
|
+
* Creates a runtime instance from a validated configuration.
|
|
840
432
|
*/
|
|
841
|
-
|
|
433
|
+
static fromConfig<TConfig extends IgniterJobsConfig<any, any, any>>(config: TConfig): IgniterJobsRuntime<TConfig>;
|
|
842
434
|
}
|
|
843
435
|
|
|
844
436
|
/**
|
|
845
|
-
* @fileoverview
|
|
846
|
-
* @module @igniter-js/jobs/core/igniter-
|
|
437
|
+
* @fileoverview Public queue entry point for @igniter-js/jobs
|
|
438
|
+
* @module @igniter-js/jobs/core/igniter-queue
|
|
847
439
|
*/
|
|
848
440
|
|
|
849
441
|
/**
|
|
850
|
-
*
|
|
851
|
-
*/
|
|
852
|
-
interface IgniterJobsRuntimeConfig<TContext, TQueues extends Record<string, IgniterQueueBuilderState<TContext, any, any>>, TScope extends string, TActor extends string> {
|
|
853
|
-
adapter: IgniterJobsAdapter;
|
|
854
|
-
context: () => TContext | Promise<TContext>;
|
|
855
|
-
queues: TQueues;
|
|
856
|
-
scope?: {
|
|
857
|
-
key: TScope;
|
|
858
|
-
options?: IgniterJobScopeOptions;
|
|
859
|
-
};
|
|
860
|
-
actor?: {
|
|
861
|
-
key: TActor;
|
|
862
|
-
options?: IgniterJobActorOptions;
|
|
863
|
-
};
|
|
864
|
-
telemetry?: IgniterTelemetry;
|
|
865
|
-
logger?: IgniterLogger;
|
|
866
|
-
defaults?: {
|
|
867
|
-
retry?: {
|
|
868
|
-
attempts?: number;
|
|
869
|
-
backoff?: any;
|
|
870
|
-
};
|
|
871
|
-
timeout?: number;
|
|
872
|
-
removeOnComplete?: boolean | {
|
|
873
|
-
count?: number;
|
|
874
|
-
age?: number;
|
|
875
|
-
};
|
|
876
|
-
removeOnFail?: boolean | {
|
|
877
|
-
count?: number;
|
|
878
|
-
age?: number;
|
|
879
|
-
};
|
|
880
|
-
};
|
|
881
|
-
}
|
|
882
|
-
/**
|
|
883
|
-
* Main runtime class for IgniterJobs.
|
|
884
|
-
* Creates proxy-based API for type-safe job access.
|
|
442
|
+
* Queue facade that exposes the fluent queue builder API.
|
|
885
443
|
*/
|
|
886
|
-
declare class
|
|
887
|
-
private readonly config;
|
|
888
|
-
private readonly queueNames;
|
|
889
|
-
constructor(config: IgniterJobsRuntimeConfig<TContext, TQueues, TScope, TActor>);
|
|
890
|
-
/**
|
|
891
|
-
* Create the main proxy that provides queue access and global methods.
|
|
892
|
-
*/
|
|
893
|
-
private createProxy;
|
|
894
|
-
/**
|
|
895
|
-
* Create a proxy for a specific queue.
|
|
896
|
-
*/
|
|
897
|
-
private createQueueProxy;
|
|
898
|
-
/**
|
|
899
|
-
* Create a proxy for a specific job.
|
|
900
|
-
*/
|
|
901
|
-
private createJobProxy;
|
|
902
|
-
/**
|
|
903
|
-
* Dispatch a job.
|
|
904
|
-
*/
|
|
905
|
-
private dispatchJob;
|
|
906
|
-
/**
|
|
907
|
-
* Schedule a job for future execution.
|
|
908
|
-
*/
|
|
909
|
-
private scheduleJob;
|
|
444
|
+
declare class IgniterQueue {
|
|
910
445
|
/**
|
|
911
|
-
*
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
*
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
*
|
|
920
|
-
*/
|
|
921
|
-
private createQueueManagement;
|
|
922
|
-
/**
|
|
923
|
-
* Pause a specific job type.
|
|
924
|
-
*/
|
|
925
|
-
private pauseJobType;
|
|
926
|
-
/**
|
|
927
|
-
* Resume a specific job type.
|
|
928
|
-
*/
|
|
929
|
-
private resumeJobType;
|
|
930
|
-
/**
|
|
931
|
-
* Subscribe to events for a specific job.
|
|
932
|
-
*/
|
|
933
|
-
private subscribeToJob;
|
|
934
|
-
/**
|
|
935
|
-
* Create queue-level subscribe.
|
|
936
|
-
*/
|
|
937
|
-
private createQueueSubscribe;
|
|
938
|
-
/**
|
|
939
|
-
* List jobs in a queue.
|
|
940
|
-
*/
|
|
941
|
-
private listQueueJobs;
|
|
942
|
-
/**
|
|
943
|
-
* Create global subscribe.
|
|
944
|
-
*/
|
|
945
|
-
private createGlobalSubscribe;
|
|
946
|
-
/**
|
|
947
|
-
* Create search function.
|
|
948
|
-
*/
|
|
949
|
-
private createSearch;
|
|
950
|
-
/**
|
|
951
|
-
* Create worker builder.
|
|
952
|
-
*/
|
|
953
|
-
private createWorkerBuilder;
|
|
954
|
-
/**
|
|
955
|
-
* Create the job handler function for workers.
|
|
956
|
-
*/
|
|
957
|
-
private createJobHandler;
|
|
958
|
-
/**
|
|
959
|
-
* Shutdown the jobs instance.
|
|
446
|
+
* Creates a new queue builder for the given name.
|
|
447
|
+
*
|
|
448
|
+
* @example
|
|
449
|
+
* ```typescript
|
|
450
|
+
* const queue = IgniterQueue.create('email')
|
|
451
|
+
* .withContext<AppContext>()
|
|
452
|
+
* .addJob('sendWelcome', { handler: async () => {} })
|
|
453
|
+
* .build()
|
|
454
|
+
* ```
|
|
960
455
|
*/
|
|
961
|
-
|
|
456
|
+
static create<const TName extends string>(name: TName): IgniterQueueBuilder<unknown, {}, {}, TName>;
|
|
962
457
|
}
|
|
963
458
|
|
|
964
459
|
/**
|
|
965
|
-
* @fileoverview
|
|
966
|
-
* @module @igniter-js/jobs/
|
|
460
|
+
* @fileoverview Telemetry event definitions for @igniter-js/jobs
|
|
461
|
+
* @module @igniter-js/jobs/telemetry/jobs.telemetry
|
|
462
|
+
*
|
|
463
|
+
* @description
|
|
464
|
+
* Defines all telemetry events emitted by the jobs package during job
|
|
465
|
+
* lifecycle operations. These events can be consumed by any transport
|
|
466
|
+
* adapter configured on the telemetry instance.
|
|
467
|
+
*
|
|
468
|
+
* Events follow the pattern: igniter.jobs.<group>.<event>
|
|
469
|
+
*
|
|
470
|
+
* Groups:
|
|
471
|
+
* - job: Job lifecycle events (enqueued, started, completed, failed, progress, retrying)
|
|
472
|
+
* - worker: Worker lifecycle events (started, stopped, idle)
|
|
473
|
+
* - queue: Queue management events (paused, resumed, drained, cleaned)
|
|
474
|
+
*
|
|
475
|
+
* @example
|
|
476
|
+
* ```typescript
|
|
477
|
+
* import { IgniterTelemetry } from '@igniter-js/telemetry'
|
|
478
|
+
* import { IgniterJobsTelemetryEvents } from '@igniter-js/jobs'
|
|
479
|
+
*
|
|
480
|
+
* const telemetry = IgniterTelemetry.create()
|
|
481
|
+
* .withService('my-api')
|
|
482
|
+
* .addEvents(IgniterJobsTelemetryEvents)
|
|
483
|
+
* .build()
|
|
484
|
+
* ```
|
|
967
485
|
*/
|
|
968
|
-
|
|
969
486
|
/**
|
|
970
|
-
*
|
|
971
|
-
*
|
|
487
|
+
* Telemetry event definitions for @igniter-js/jobs.
|
|
488
|
+
*
|
|
489
|
+
* This descriptor can be passed to `IgniterTelemetry.addEvents()` to register
|
|
490
|
+
* all job-related telemetry events with proper type inference.
|
|
491
|
+
*
|
|
492
|
+
* Event names follow the pattern: `igniter.jobs.<group>.<event>`
|
|
972
493
|
*
|
|
973
494
|
* @example
|
|
974
495
|
* ```typescript
|
|
975
|
-
*
|
|
976
|
-
*
|
|
977
|
-
*
|
|
978
|
-
*
|
|
979
|
-
*
|
|
980
|
-
*
|
|
981
|
-
*
|
|
982
|
-
*
|
|
983
|
-
*
|
|
984
|
-
*
|
|
985
|
-
*
|
|
986
|
-
*
|
|
987
|
-
*
|
|
988
|
-
*
|
|
496
|
+
* import { IgniterTelemetry } from '@igniter-js/telemetry'
|
|
497
|
+
* import { IgniterJobsTelemetryEvents } from '@igniter-js/jobs'
|
|
498
|
+
*
|
|
499
|
+
* const telemetry = IgniterTelemetry.create()
|
|
500
|
+
* .withService('my-api')
|
|
501
|
+
* .addEvents(IgniterJobsTelemetryEvents)
|
|
502
|
+
* .build()
|
|
503
|
+
*
|
|
504
|
+
* // Type-safe emit
|
|
505
|
+
* telemetry.emit('igniter.jobs.job.completed', {
|
|
506
|
+
* attributes: {
|
|
507
|
+
* 'ctx.job.id': 'job_123',
|
|
508
|
+
* 'ctx.job.name': 'sendWelcome',
|
|
509
|
+
* 'ctx.job.queue': 'email',
|
|
510
|
+
* 'ctx.job.duration': 1500,
|
|
511
|
+
* },
|
|
512
|
+
* })
|
|
989
513
|
* ```
|
|
990
514
|
*/
|
|
991
|
-
declare const
|
|
992
|
-
readonly
|
|
993
|
-
readonly
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
515
|
+
declare const IgniterJobsTelemetryEvents: {
|
|
516
|
+
readonly namespace: "igniter.jobs";
|
|
517
|
+
readonly events: {
|
|
518
|
+
readonly job: {
|
|
519
|
+
readonly enqueued: {
|
|
520
|
+
"ctx.job.id": string;
|
|
521
|
+
"ctx.job.name": string;
|
|
522
|
+
"ctx.job.queue": string;
|
|
523
|
+
"ctx.job.priority"?: number;
|
|
524
|
+
"ctx.job.delay"?: number;
|
|
525
|
+
};
|
|
526
|
+
readonly started: {
|
|
527
|
+
"ctx.job.id": string;
|
|
528
|
+
"ctx.job.name": string;
|
|
529
|
+
"ctx.job.queue": string;
|
|
530
|
+
"ctx.job.attempt": number;
|
|
531
|
+
"ctx.job.maxAttempts": number;
|
|
532
|
+
};
|
|
533
|
+
readonly completed: {
|
|
534
|
+
"ctx.job.id": string;
|
|
535
|
+
"ctx.job.name": string;
|
|
536
|
+
"ctx.job.queue": string;
|
|
537
|
+
"ctx.job.duration": number;
|
|
538
|
+
};
|
|
539
|
+
readonly failed: {
|
|
540
|
+
"ctx.job.id": string;
|
|
541
|
+
"ctx.job.name": string;
|
|
542
|
+
"ctx.job.queue": string;
|
|
543
|
+
"ctx.job.error.message": string;
|
|
544
|
+
"ctx.job.error.code"?: string;
|
|
545
|
+
"ctx.job.attempt": number;
|
|
546
|
+
"ctx.job.maxAttempts": number;
|
|
547
|
+
"ctx.job.isFinalAttempt": boolean;
|
|
548
|
+
};
|
|
549
|
+
readonly progress: {
|
|
550
|
+
"ctx.job.id": string;
|
|
551
|
+
"ctx.job.name": string;
|
|
552
|
+
"ctx.job.queue": string;
|
|
553
|
+
"ctx.job.progress": number;
|
|
554
|
+
"ctx.job.progress.message"?: string;
|
|
555
|
+
};
|
|
556
|
+
readonly retrying: {
|
|
557
|
+
"ctx.job.id": string;
|
|
558
|
+
"ctx.job.name": string;
|
|
559
|
+
"ctx.job.queue": string;
|
|
560
|
+
"ctx.job.attempt": number;
|
|
561
|
+
"ctx.job.maxAttempts": number;
|
|
562
|
+
"ctx.job.nextRetryDelay": number;
|
|
563
|
+
};
|
|
564
|
+
readonly scheduled: {
|
|
565
|
+
"ctx.job.id": string;
|
|
566
|
+
"ctx.job.name": string;
|
|
567
|
+
"ctx.job.queue": string;
|
|
568
|
+
"ctx.job.scheduledAt"?: string;
|
|
569
|
+
"ctx.job.cron"?: string;
|
|
570
|
+
};
|
|
571
|
+
};
|
|
572
|
+
readonly worker: {
|
|
573
|
+
readonly started: {
|
|
574
|
+
"ctx.worker.id": string;
|
|
575
|
+
"ctx.worker.queues": string;
|
|
576
|
+
"ctx.worker.concurrency": number;
|
|
577
|
+
};
|
|
578
|
+
readonly stopped: {
|
|
579
|
+
"ctx.worker.id": string;
|
|
580
|
+
"ctx.worker.processed": number;
|
|
581
|
+
"ctx.worker.failed": number;
|
|
582
|
+
"ctx.worker.uptime": number;
|
|
583
|
+
};
|
|
584
|
+
readonly idle: {
|
|
585
|
+
"ctx.worker.id": string;
|
|
586
|
+
"ctx.worker.queues": string;
|
|
587
|
+
};
|
|
588
|
+
readonly paused: {
|
|
589
|
+
"ctx.worker.id": string;
|
|
590
|
+
"ctx.worker.queues": string;
|
|
591
|
+
};
|
|
592
|
+
readonly resumed: {
|
|
593
|
+
"ctx.worker.id": string;
|
|
594
|
+
"ctx.worker.queues": string;
|
|
595
|
+
};
|
|
596
|
+
};
|
|
597
|
+
readonly queue: {
|
|
598
|
+
readonly paused: {
|
|
599
|
+
"ctx.queue.name": string;
|
|
600
|
+
};
|
|
601
|
+
readonly resumed: {
|
|
602
|
+
"ctx.queue.name": string;
|
|
603
|
+
};
|
|
604
|
+
readonly drained: {
|
|
605
|
+
"ctx.queue.name": string;
|
|
606
|
+
"ctx.queue.drained.count": number;
|
|
607
|
+
};
|
|
608
|
+
readonly cleaned: {
|
|
609
|
+
"ctx.queue.name": string;
|
|
610
|
+
"ctx.queue.cleaned.count": number;
|
|
611
|
+
"ctx.queue.cleaned.status": string;
|
|
612
|
+
};
|
|
613
|
+
readonly obliterated: {
|
|
614
|
+
"ctx.queue.name": string;
|
|
615
|
+
"ctx.queue.obliterated.force": boolean;
|
|
616
|
+
};
|
|
617
|
+
};
|
|
618
|
+
};
|
|
1042
619
|
};
|
|
1043
620
|
/**
|
|
1044
|
-
*
|
|
1045
|
-
*/
|
|
1046
|
-
type IgniterJobsErrorCode = keyof typeof IGNITER_JOBS_ERROR_CODES;
|
|
1047
|
-
/**
|
|
1048
|
-
* Options for creating an IgniterJobsError.
|
|
1049
|
-
*/
|
|
1050
|
-
interface IgniterJobsErrorOptions {
|
|
1051
|
-
/**
|
|
1052
|
-
* Error code from IGNITER_JOBS_ERROR_CODES.
|
|
1053
|
-
*/
|
|
1054
|
-
code: IgniterJobsErrorCode;
|
|
1055
|
-
/**
|
|
1056
|
-
* Human-readable error message.
|
|
1057
|
-
*/
|
|
1058
|
-
message: string;
|
|
1059
|
-
/**
|
|
1060
|
-
* HTTP status code (for REST API responses).
|
|
1061
|
-
* @default 500
|
|
1062
|
-
*/
|
|
1063
|
-
statusCode?: number;
|
|
1064
|
-
/**
|
|
1065
|
-
* Original error that caused this error.
|
|
1066
|
-
*/
|
|
1067
|
-
cause?: Error;
|
|
1068
|
-
/**
|
|
1069
|
-
* Additional details for debugging.
|
|
1070
|
-
*/
|
|
1071
|
-
details?: Record<string, unknown>;
|
|
1072
|
-
/**
|
|
1073
|
-
* Logger instance for logging the error.
|
|
1074
|
-
*/
|
|
1075
|
-
logger?: IgniterLogger;
|
|
1076
|
-
}
|
|
1077
|
-
/**
|
|
1078
|
-
* Custom error class for @igniter-js/jobs.
|
|
1079
|
-
* Extends IgniterError for consistent error handling across the Igniter ecosystem.
|
|
621
|
+
* Union type of all job telemetry event names.
|
|
1080
622
|
*
|
|
1081
623
|
* @example
|
|
1082
624
|
* ```typescript
|
|
1083
|
-
*
|
|
1084
|
-
*
|
|
1085
|
-
*
|
|
1086
|
-
*
|
|
1087
|
-
*
|
|
1088
|
-
* })
|
|
625
|
+
* import type { IgniterJobsTelemetryEventNames } from '@igniter-js/jobs'
|
|
626
|
+
*
|
|
627
|
+
* function handleEvent(name: IgniterJobsTelemetryEventNames) {
|
|
628
|
+
* // name is type-safe
|
|
629
|
+
* }
|
|
1089
630
|
* ```
|
|
1090
631
|
*/
|
|
1091
|
-
|
|
1092
|
-
/**
|
|
1093
|
-
* Error code for programmatic handling.
|
|
1094
|
-
*/
|
|
1095
|
-
readonly code: IgniterJobsErrorCode;
|
|
1096
|
-
/**
|
|
1097
|
-
* Additional error details.
|
|
1098
|
-
*/
|
|
1099
|
-
readonly details?: Record<string, unknown>;
|
|
1100
|
-
constructor(options: IgniterJobsErrorOptions);
|
|
1101
|
-
/**
|
|
1102
|
-
* Convert error to a plain object for serialization.
|
|
1103
|
-
*/
|
|
1104
|
-
toJSON(): Record<string, unknown>;
|
|
1105
|
-
}
|
|
632
|
+
type IgniterJobsTelemetryEventNames = "igniter.jobs.job.enqueued" | "igniter.jobs.job.started" | "igniter.jobs.job.completed" | "igniter.jobs.job.failed" | "igniter.jobs.job.progress" | "igniter.jobs.job.retrying" | "igniter.jobs.job.scheduled" | "igniter.jobs.worker.started" | "igniter.jobs.worker.stopped" | "igniter.jobs.worker.idle" | "igniter.jobs.worker.paused" | "igniter.jobs.worker.resumed" | "igniter.jobs.queue.paused" | "igniter.jobs.queue.resumed" | "igniter.jobs.queue.drained" | "igniter.jobs.queue.cleaned" | "igniter.jobs.queue.obliterated";
|
|
1106
633
|
|
|
1107
|
-
export {
|
|
634
|
+
export { IGNITER_JOBS_ERROR_CODES, IgniterCronDefinition, IgniterJobDefinition, IgniterJobSearchResult, IgniterJobStatus, IgniterJobs, IgniterJobsAdapter, type IgniterJobsBaseRuntime, IgniterJobsBuilder, type IgniterJobsBuilderState, type IgniterJobsConfig, IgniterJobsDispatchParams, IgniterJobsError, type IgniterJobsErrorCode, type IgniterJobsErrorOptions, IgniterJobsEventHandler, type IgniterJobsInferCronResult, type IgniterJobsInferInput, type IgniterJobsInferJobInput, IgniterJobsInferSchemaInput, type IgniterJobsJobAccessor, type IgniterJobsJobInstanceAccessor, type IgniterJobsJobManyAccessor, IgniterJobsLimiter, IgniterJobsQueue, type IgniterJobsQueueAccessor, IgniterJobsQueueCleanOptions, IgniterJobsQueueInfo, type IgniterJobsQueueManagerAccessor, type IgniterJobsRuntime, IgniterJobsScheduleParams, IgniterJobsSchema, IgniterJobsScopeDefinition, IgniterJobsScopeOptions, IgniterJobsTelemetry, type IgniterJobsTelemetryEventNames, IgniterJobsTelemetryEvents, type IgniterJobsWorkerBuilderAccessor, IgniterJobsWorkerBuilderConfig, type IgniterJobsWorkerFluentBuilder, IgniterJobsWorkerHandle, IgniterJobsWorkerHandlers, IgniterQueue, IgniterQueueBuilder, IgniterWorkerBuilder };
|