@odunlamizo/node-river 1.0.4 → 1.0.6
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/README.md +1 -1
- package/dist/driver-okKFbSrB.d.ts +54 -0
- package/dist/driver-vSyPLsFq.d.cts +54 -0
- package/dist/drivers/pg/index.cjs +224 -0
- package/dist/drivers/pg/index.cjs.map +1 -0
- package/dist/drivers/pg/index.d.cts +46 -0
- package/dist/drivers/pg/index.d.ts +46 -0
- package/dist/drivers/pg/index.js +218 -0
- package/dist/drivers/pg/index.js.map +1 -0
- package/dist/index.cjs +5 -29
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +4 -301
- package/dist/index.d.ts +4 -301
- package/dist/index.js +4 -3
- package/dist/index.js.map +1 -0
- package/dist/insert-result-Bf0bAFvJ.d.cts +238 -0
- package/dist/insert-result-Bf0bAFvJ.d.ts +238 -0
- package/dist/types.cjs +18 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.cts +18 -0
- package/dist/types.d.ts +18 -0
- package/dist/types.js +16 -0
- package/dist/types.js.map +1 -0
- package/package.json +21 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,304 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
*/
|
|
6
|
-
interface ClientConfiguration {
|
|
7
|
-
/**
|
|
8
|
-
* Default queue name for job insertion
|
|
9
|
-
*/
|
|
10
|
-
defaultQueue?: string;
|
|
11
|
-
/**
|
|
12
|
-
* Maximum number of attempts for jobs
|
|
13
|
-
*/
|
|
14
|
-
maxAttempts?: number;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Represents the lifecycle state of a job, such as available, running, completed, or scheduled.
|
|
19
|
-
*/
|
|
20
|
-
declare enum JobState {
|
|
21
|
-
/**
|
|
22
|
-
* Immediately eligible to be worked
|
|
23
|
-
*/
|
|
24
|
-
Available = "available",
|
|
25
|
-
/**
|
|
26
|
-
* Manually cancelled by user; cleaned after a period
|
|
27
|
-
*/
|
|
28
|
-
Cancelled = "cancelled",
|
|
29
|
-
/**
|
|
30
|
-
* Successfully run to completion; cleaned after a period
|
|
31
|
-
*/
|
|
32
|
-
Completed = "completed",
|
|
33
|
-
/**
|
|
34
|
-
* Errored too many times; needs manual intervention
|
|
35
|
-
*/
|
|
36
|
-
Discarded = "discarded",
|
|
37
|
-
/**
|
|
38
|
-
* Waiting for external action; not worked or deleted until moved
|
|
39
|
-
*/
|
|
40
|
-
Pending = "pending",
|
|
41
|
-
/**
|
|
42
|
-
* Errored but will be retried; becomes Available when ready
|
|
43
|
-
*/
|
|
44
|
-
Retryable = "retryable",
|
|
45
|
-
/**
|
|
46
|
-
* Actively running; may need rescue if stuck
|
|
47
|
-
*/
|
|
48
|
-
Running = "running",
|
|
49
|
-
/**
|
|
50
|
-
* Scheduled for future execution; becomes Available when due
|
|
51
|
-
*/
|
|
52
|
-
Scheduled = "scheduled"
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Represents a failed job attempt, including error details and stack trace.
|
|
57
|
-
*/
|
|
58
|
-
interface AttemptError {
|
|
59
|
-
/**
|
|
60
|
-
* Time the error occurred
|
|
61
|
-
*/
|
|
62
|
-
at: string;
|
|
63
|
-
/**
|
|
64
|
-
* Attempt number when the error occurred
|
|
65
|
-
*/
|
|
66
|
-
attempt: number;
|
|
67
|
-
/**
|
|
68
|
-
* Stringified error or panic value
|
|
69
|
-
*/
|
|
70
|
-
error: string;
|
|
71
|
-
/**
|
|
72
|
-
* Stack trace from a job that panicked
|
|
73
|
-
*/
|
|
74
|
-
trace: string;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Options for enforcing uniqueness constraints on jobs.
|
|
79
|
-
*/
|
|
80
|
-
interface UniqueOpts {
|
|
81
|
-
/**
|
|
82
|
-
* Enforce uniqueness based on job arguments.
|
|
83
|
-
* True for all args, or specify keys to include.
|
|
84
|
-
*/
|
|
85
|
-
byArgs?: true | string[];
|
|
86
|
-
/**
|
|
87
|
-
* Enforce uniqueness within a time period (seconds).
|
|
88
|
-
*/
|
|
89
|
-
byPeriod?: number;
|
|
90
|
-
/**
|
|
91
|
-
* Enforce uniqueness within each queue.
|
|
92
|
-
*/
|
|
93
|
-
byQueue?: true;
|
|
94
|
-
/**
|
|
95
|
-
* Enforce uniqueness across specified job states.
|
|
96
|
-
*/
|
|
97
|
-
byState?: string[];
|
|
98
|
-
/**
|
|
99
|
-
* Exclude job kind from uniqueness computation.
|
|
100
|
-
*/
|
|
101
|
-
excludeKind?: true;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Options for job insertion, such as queue, priority, scheduling, and metadata.
|
|
106
|
-
*/
|
|
107
|
-
interface InsertOpts {
|
|
108
|
-
/**
|
|
109
|
-
* List of tags for grouping and categorizing jobs
|
|
110
|
-
*/
|
|
111
|
-
tags?: string[];
|
|
112
|
-
/**
|
|
113
|
-
* Name of the job queue to insert into
|
|
114
|
-
*/
|
|
115
|
-
queue?: string;
|
|
116
|
-
/**
|
|
117
|
-
* Job priority (1 = highest, 4 = lowest)
|
|
118
|
-
*/
|
|
119
|
-
priority?: number;
|
|
120
|
-
/**
|
|
121
|
-
* Arbitrary metadata for the job
|
|
122
|
-
*/
|
|
123
|
-
metadata?: Record<string, unknown>;
|
|
124
|
-
/**
|
|
125
|
-
* Maximum number of attempts before discarding the job
|
|
126
|
-
*/
|
|
127
|
-
maxAttempts?: number;
|
|
128
|
-
/**
|
|
129
|
-
* Schedule the job for future execution
|
|
130
|
-
*/
|
|
131
|
-
scheduledAt?: Date;
|
|
132
|
-
/**
|
|
133
|
-
* Options relating to job uniqueness.
|
|
134
|
-
* If not set, the job is never treated as unique.
|
|
135
|
-
*/
|
|
136
|
-
uniqueOpts?: UniqueOpts;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Interface for job argument objects passed to job handlers.
|
|
141
|
-
*
|
|
142
|
-
* Every job must specify a `kind` to identify its type, and can include
|
|
143
|
-
* any number of additional properties relevant to the job's execution.
|
|
144
|
-
*/
|
|
145
|
-
interface JobArgs {
|
|
146
|
-
/**
|
|
147
|
-
* Identifies the job type for routing and processing.
|
|
148
|
-
*/
|
|
149
|
-
kind: string;
|
|
150
|
-
/**
|
|
151
|
-
* Arbitrary job parameters, allowing for flexible job payloads.
|
|
152
|
-
* All values should be JSON-compatible.
|
|
153
|
-
*/
|
|
154
|
-
[key: string]: unknown;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Represents a job persisted in the database, including its state, metadata, and scheduling information.
|
|
159
|
-
*/
|
|
160
|
-
interface Job<T extends JobArgs = JobArgs> {
|
|
161
|
-
/**
|
|
162
|
-
* Unique job ID, generated by the database
|
|
163
|
-
*/
|
|
164
|
-
id: number;
|
|
165
|
-
/**
|
|
166
|
-
* Current state of the job (e.g., available, completed)
|
|
167
|
-
*/
|
|
168
|
-
state: JobState;
|
|
169
|
-
/**
|
|
170
|
-
* Current attempt number, incremented each time the job is worked
|
|
171
|
-
*/
|
|
172
|
-
attempt: number;
|
|
173
|
-
/**
|
|
174
|
-
* Maximum number of attempts before the job stops retrying
|
|
175
|
-
*/
|
|
176
|
-
maxAttempts: number;
|
|
177
|
-
/**
|
|
178
|
-
* Last time the job was worked, null if never
|
|
179
|
-
*/
|
|
180
|
-
attemptedAt: Date | null;
|
|
181
|
-
/**
|
|
182
|
-
* When the job record was created
|
|
183
|
-
*/
|
|
184
|
-
createdAt: Date;
|
|
185
|
-
/**
|
|
186
|
-
* When the job was finalized (completed or errored for last time), null if not finalized
|
|
187
|
-
*/
|
|
188
|
-
finalizedAt: Date | null;
|
|
189
|
-
/**
|
|
190
|
-
* When the job is scheduled to become available
|
|
191
|
-
*/
|
|
192
|
-
scheduledAt: Date;
|
|
193
|
-
/**
|
|
194
|
-
* Job priority (1 = highest, 4 = lowest)
|
|
195
|
-
*/
|
|
196
|
-
priority: number;
|
|
197
|
-
/**
|
|
198
|
-
* Job arguments, decoded from JSON
|
|
199
|
-
*/
|
|
200
|
-
args: T;
|
|
201
|
-
/**
|
|
202
|
-
* Worker IDs that have worked this job, null if never
|
|
203
|
-
*/
|
|
204
|
-
attemptedBy: string[] | null;
|
|
205
|
-
/**
|
|
206
|
-
* Errors for each attempt, ordered earliest to latest, null if none
|
|
207
|
-
*/
|
|
208
|
-
errors: AttemptError[] | null;
|
|
209
|
-
/**
|
|
210
|
-
* Job type identifier, set at insertion
|
|
211
|
-
*/
|
|
212
|
-
kind: string;
|
|
213
|
-
/**
|
|
214
|
-
* Arbitrary metadata associated with the job
|
|
215
|
-
*/
|
|
216
|
-
metadata: Record<string, unknown>;
|
|
217
|
-
/**
|
|
218
|
-
* Name of the queue where the job will be worked
|
|
219
|
-
*/
|
|
220
|
-
queue: string;
|
|
221
|
-
/**
|
|
222
|
-
* List of tags for grouping and categorizing jobs
|
|
223
|
-
*/
|
|
224
|
-
tags: string[];
|
|
225
|
-
/**
|
|
226
|
-
* Unique key for job within its kind, used for unique insertions, null if not set
|
|
227
|
-
*/
|
|
228
|
-
uniqueKey: Buffer | null;
|
|
229
|
-
/**
|
|
230
|
-
* States required for uniqueness, null if not set
|
|
231
|
-
*/
|
|
232
|
-
uniqueStates: JobState[] | null;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
/**
|
|
236
|
-
* Result of a job insertion operation.
|
|
237
|
-
*
|
|
238
|
-
* - If a unique job already exists, `job` is the existing job and `skipped` is true.
|
|
239
|
-
* - If the job was inserted, `job` is the new job and `skipped` is false.
|
|
240
|
-
*/
|
|
241
|
-
interface InsertResult<T extends JobArgs = JobArgs> {
|
|
242
|
-
/**
|
|
243
|
-
* The inserted job, or the existing job if insertion was skipped due to uniqueness.
|
|
244
|
-
*/
|
|
245
|
-
job: Job<T>;
|
|
246
|
-
/**
|
|
247
|
-
* True if insertion was skipped because a unique job already exists.
|
|
248
|
-
*/
|
|
249
|
-
skipped: boolean;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
/**
|
|
253
|
-
* Common interface for all RiverQueue drivers (e.g., Postgres, Prisma, Sequelize, etc.).
|
|
254
|
-
* The generic parameter Tx must be set to the driver's transaction/session type.
|
|
255
|
-
*/
|
|
256
|
-
interface Driver<Tx> {
|
|
257
|
-
/**
|
|
258
|
-
* Checks if the driver can connect to the database. Throws on failure.
|
|
259
|
-
*/
|
|
260
|
-
verifyConnection(): Promise<void>;
|
|
261
|
-
/**
|
|
262
|
-
* Closes all database connections and cleans up resources.
|
|
263
|
-
*/
|
|
264
|
-
close(): Promise<void>;
|
|
265
|
-
/**
|
|
266
|
-
* Inserts a new job into the queue using the provided arguments and options.
|
|
267
|
-
* @param args - The job arguments to insert.
|
|
268
|
-
* @param opts - Options for job insertion.
|
|
269
|
-
* @returns A promise that resolves to the result of the insertion operation,
|
|
270
|
-
* including the job and whether the insert was skipped due to uniqueness.
|
|
271
|
-
*/
|
|
272
|
-
insert<T extends JobArgs>(args: T, opts: InsertOpts): Promise<InsertResult<T>>;
|
|
273
|
-
/**
|
|
274
|
-
* Inserts a new job into the queue within an existing transaction or session.
|
|
275
|
-
* The type of `tx` is driver-specific and should match the transaction/session type for the driver.
|
|
276
|
-
*
|
|
277
|
-
* @param tx - The transaction or session object to use for the insert.
|
|
278
|
-
* @param args - The job arguments to insert.
|
|
279
|
-
* @param opts - Options for job insertion.
|
|
280
|
-
* @returns A promise that resolves to the result of the insertion operation.
|
|
281
|
-
*/
|
|
282
|
-
insertTx<T extends JobArgs>(tx: Tx, args: T, opts: InsertOpts): Promise<InsertResult<T>>;
|
|
283
|
-
/**
|
|
284
|
-
* Inserts multiple jobs in sequence within a single transaction.
|
|
285
|
-
* If any insert fails, all previous inserts in the batch are rolled back.
|
|
286
|
-
*
|
|
287
|
-
* @param jobs - Array of job argument and option pairs to insert.
|
|
288
|
-
* @returns Array of InsertResult objects for each job.
|
|
289
|
-
*/
|
|
290
|
-
insertMany<T extends JobArgs>(jobs: {
|
|
291
|
-
args: T;
|
|
292
|
-
opts: InsertOpts;
|
|
293
|
-
}[]): Promise<InsertResult<T>[]>;
|
|
294
|
-
/**
|
|
295
|
-
* Starts and returns a new transaction or session object for the driver.
|
|
296
|
-
* The returned object should be used for transactional operations such as insertTx.
|
|
297
|
-
*
|
|
298
|
-
* @returns A promise that resolves to the driver's transaction/session object.
|
|
299
|
-
*/
|
|
300
|
-
getTx(): Promise<Tx>;
|
|
301
|
-
}
|
|
1
|
+
import { D as Driver } from './driver-okKFbSrB.js';
|
|
2
|
+
import { ClientConfiguration } from './types.js';
|
|
3
|
+
import { J as JobArgs, I as InsertOpts, a as InsertResult } from './insert-result-Bf0bAFvJ.js';
|
|
4
|
+
import 'buffer';
|
|
302
5
|
|
|
303
6
|
/**
|
|
304
7
|
* Provides methods to enqueue jobs and manage queue operations.
|
package/dist/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/client.ts"],"names":[],"mappings":";AAMA,IAAqB,cAArB,MAA2D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASzD,WAAA,CAAY,QAAW,aAAA,EAAoC;AACzD,IAAA,IAAA,CAAK,MAAA,GAAS,MAAA;AACd,IAAA,IAAA,CAAK,aAAA,GAAgB,aAAA;AAAA,EACvB;AAAA;AAAA;AAAA;AAAA,EAKA,gBAAA,GAAkC;AAChC,IAAA,OAAO,IAAA,CAAK,OAAO,gBAAA,EAAiB;AAAA,EACtC;AAAA;AAAA;AAAA;AAAA,EAKA,KAAA,GAAuB;AACrB,IAAA,OAAO,IAAA,CAAK,OAAO,KAAA,EAAM;AAAA,EAC3B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAA,CAA0B,IAAA,EAAS,IAAA,GAAmB,EAAC,EAA6B;AAClF,IAAA,MAAM,WAAA,GAA0B;AAAA,MAC9B,KAAA,EAAO,KAAK,aAAA,CAAc,YAAA;AAAA,MAC1B,WAAA,EAAa,KAAK,aAAA,CAAc,WAAA;AAAA,MAChC,GAAG;AAAA,KACL;AAEA,IAAA,OAAO,IAAA,CAAK,MAAA,CAAO,MAAA,CAAO,IAAA,EAAM,WAAW,CAAA;AAAA,EAC7C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYA,QAAA,CAA4B,EAAA,EAAQ,IAAA,EAAS,IAAA,GAAmB,EAAC,EAA6B;AAC5F,IAAA,MAAM,WAAA,GAA0B;AAAA,MAC9B,KAAA,EAAO,KAAK,aAAA,CAAc,YAAA;AAAA,MAC1B,WAAA,EAAa,KAAK,aAAA,CAAc,WAAA;AAAA,MAChC,GAAG;AAAA,KACL;AAEA,IAAA,OAAO,IAAA,CAAK,MAAA,CAAO,QAAA,CAAS,EAAA,EAAI,MAAM,WAAW,CAAA;AAAA,EACnD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAM,WACJ,IAAA,EAC4B;AAC5B,IAAA,MAAM,gBAAA,GAAmB,IAAA,CAAK,GAAA,CAAI,CAAC,GAAA,MAAS;AAAA,MAC1C,MAAM,GAAA,CAAI,IAAA;AAAA,MACV,IAAA,EAAM;AAAA,QACJ,KAAA,EAAO,KAAK,aAAA,CAAc,YAAA;AAAA,QAC1B,WAAA,EAAa,KAAK,aAAA,CAAc,WAAA;AAAA,QAChC,GAAG,GAAA,CAAI;AAAA;AACT,KACF,CAAE,CAAA;AAEF,IAAA,OAAO,IAAA,CAAK,MAAA,CAAO,UAAA,CAAW,gBAAgB,CAAA;AAAA,EAChD;AACF","file":"index.js","sourcesContent":["import { Driver } from './drivers';\nimport { ClientConfiguration, InsertOpts, InsertResult, JobArgs } from './types';\n\n/**\n * Provides methods to enqueue jobs and manage queue operations.\n */\nexport default class RiverClient<D extends Driver<Tx>, Tx> {\n private readonly driver: D;\n private readonly configuration: ClientConfiguration;\n\n /**\n * Creates a new RiverClient instance.\n * @param driver - The queue driver implementation.\n * @param configuration - Client configuration options.\n */\n constructor(driver: D, configuration: ClientConfiguration) {\n this.driver = driver;\n this.configuration = configuration;\n }\n\n /**\n * Checks if the driver can connect to the database. Throws on failure.\n */\n verifyConnection(): Promise<void> {\n return this.driver.verifyConnection();\n }\n\n /**\n * Closes all database connections and cleans up resources.\n */\n close(): Promise<void> {\n return this.driver.close();\n }\n\n /**\n * Inserts a job into the queue with the specified arguments and options.\n * @param args - The job arguments to insert.\n * @param opts - Optional insertion options.\n * @returns A promise that resolves to the result of the insertion operation,\n * including the job and whether the insert was skipped due to uniqueness.\n */\n insert<T extends JobArgs>(args: T, opts: InsertOpts = {}): Promise<InsertResult<T>> {\n const defaultOpts: InsertOpts = {\n queue: this.configuration.defaultQueue,\n maxAttempts: this.configuration.maxAttempts,\n ...opts,\n };\n\n return this.driver.insert(args, defaultOpts);\n }\n\n /**\n * Inserts a job into the queue within an existing transaction or session.\n * The transaction type (Tx) is determined by the driver implementation.\n *\n * @param tx - The transaction or session object to use for the insert.\n * @param args - The job arguments to insert.\n * @param opts - Optional insertion options.\n * @returns A promise that resolves to the result of the insertion operation,\n * including the job and whether the insert was skipped due to uniqueness.\n */\n insertTx<T extends JobArgs>(tx: Tx, args: T, opts: InsertOpts = {}): Promise<InsertResult<T>> {\n const defaultOpts: InsertOpts = {\n queue: this.configuration.defaultQueue,\n maxAttempts: this.configuration.maxAttempts,\n ...opts,\n };\n\n return this.driver.insertTx(tx, args, defaultOpts);\n }\n\n /**\n * Inserts multiple jobs in sequence within a single transaction.\n * If any insert fails, all previous inserts in the batch are rolled back.\n *\n * @param jobs - Array of job argument and option pairs to insert.\n * @returns A promise that resolves to an array of InsertResult objects for each job.\n */\n async insertMany<T extends JobArgs>(\n jobs: { args: T; opts: InsertOpts }[],\n ): Promise<InsertResult<T>[]> {\n const jobsWithDefaults = jobs.map((job) => ({\n args: job.args,\n opts: {\n queue: this.configuration.defaultQueue,\n maxAttempts: this.configuration.maxAttempts,\n ...job.opts,\n },\n }));\n\n return this.driver.insertMany(jobsWithDefaults);\n }\n}\n"]}
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import { Buffer } from 'buffer';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Represents the lifecycle state of a job, such as available, running, completed, or scheduled.
|
|
5
|
+
*/
|
|
6
|
+
declare enum JobState {
|
|
7
|
+
/**
|
|
8
|
+
* Immediately eligible to be worked
|
|
9
|
+
*/
|
|
10
|
+
Available = "available",
|
|
11
|
+
/**
|
|
12
|
+
* Manually cancelled by user; cleaned after a period
|
|
13
|
+
*/
|
|
14
|
+
Cancelled = "cancelled",
|
|
15
|
+
/**
|
|
16
|
+
* Successfully run to completion; cleaned after a period
|
|
17
|
+
*/
|
|
18
|
+
Completed = "completed",
|
|
19
|
+
/**
|
|
20
|
+
* Errored too many times; needs manual intervention
|
|
21
|
+
*/
|
|
22
|
+
Discarded = "discarded",
|
|
23
|
+
/**
|
|
24
|
+
* Waiting for external action; not worked or deleted until moved
|
|
25
|
+
*/
|
|
26
|
+
Pending = "pending",
|
|
27
|
+
/**
|
|
28
|
+
* Errored but will be retried; becomes Available when ready
|
|
29
|
+
*/
|
|
30
|
+
Retryable = "retryable",
|
|
31
|
+
/**
|
|
32
|
+
* Actively running; may need rescue if stuck
|
|
33
|
+
*/
|
|
34
|
+
Running = "running",
|
|
35
|
+
/**
|
|
36
|
+
* Scheduled for future execution; becomes Available when due
|
|
37
|
+
*/
|
|
38
|
+
Scheduled = "scheduled"
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Represents a failed job attempt, including error details and stack trace.
|
|
43
|
+
*/
|
|
44
|
+
interface AttemptError {
|
|
45
|
+
/**
|
|
46
|
+
* Time the error occurred
|
|
47
|
+
*/
|
|
48
|
+
at: string;
|
|
49
|
+
/**
|
|
50
|
+
* Attempt number when the error occurred
|
|
51
|
+
*/
|
|
52
|
+
attempt: number;
|
|
53
|
+
/**
|
|
54
|
+
* Stringified error or panic value
|
|
55
|
+
*/
|
|
56
|
+
error: string;
|
|
57
|
+
/**
|
|
58
|
+
* Stack trace from a job that panicked
|
|
59
|
+
*/
|
|
60
|
+
trace: string;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Options for enforcing uniqueness constraints on jobs.
|
|
65
|
+
*/
|
|
66
|
+
interface UniqueOpts {
|
|
67
|
+
/**
|
|
68
|
+
* Enforce uniqueness based on job arguments.
|
|
69
|
+
* True for all args, or specify keys to include.
|
|
70
|
+
*/
|
|
71
|
+
byArgs?: true | string[];
|
|
72
|
+
/**
|
|
73
|
+
* Enforce uniqueness within a time period (seconds).
|
|
74
|
+
*/
|
|
75
|
+
byPeriod?: number;
|
|
76
|
+
/**
|
|
77
|
+
* Enforce uniqueness within each queue.
|
|
78
|
+
*/
|
|
79
|
+
byQueue?: true;
|
|
80
|
+
/**
|
|
81
|
+
* Enforce uniqueness across specified job states.
|
|
82
|
+
*/
|
|
83
|
+
byState?: string[];
|
|
84
|
+
/**
|
|
85
|
+
* Exclude job kind from uniqueness computation.
|
|
86
|
+
*/
|
|
87
|
+
excludeKind?: true;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Options for job insertion, such as queue, priority, scheduling, and metadata.
|
|
92
|
+
*/
|
|
93
|
+
interface InsertOpts {
|
|
94
|
+
/**
|
|
95
|
+
* List of tags for grouping and categorizing jobs
|
|
96
|
+
*/
|
|
97
|
+
tags?: string[];
|
|
98
|
+
/**
|
|
99
|
+
* Name of the job queue to insert into
|
|
100
|
+
*/
|
|
101
|
+
queue?: string;
|
|
102
|
+
/**
|
|
103
|
+
* Job priority (1 = highest, 4 = lowest)
|
|
104
|
+
*/
|
|
105
|
+
priority?: number;
|
|
106
|
+
/**
|
|
107
|
+
* Arbitrary metadata for the job
|
|
108
|
+
*/
|
|
109
|
+
metadata?: Record<string, unknown>;
|
|
110
|
+
/**
|
|
111
|
+
* Maximum number of attempts before discarding the job
|
|
112
|
+
*/
|
|
113
|
+
maxAttempts?: number;
|
|
114
|
+
/**
|
|
115
|
+
* Schedule the job for future execution
|
|
116
|
+
*/
|
|
117
|
+
scheduledAt?: Date;
|
|
118
|
+
/**
|
|
119
|
+
* Options relating to job uniqueness.
|
|
120
|
+
* If not set, the job is never treated as unique.
|
|
121
|
+
*/
|
|
122
|
+
uniqueOpts?: UniqueOpts;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Interface for job argument objects passed to job handlers.
|
|
127
|
+
*
|
|
128
|
+
* Every job must specify a `kind` to identify its type, and can include
|
|
129
|
+
* any number of additional properties relevant to the job's execution.
|
|
130
|
+
*/
|
|
131
|
+
interface JobArgs {
|
|
132
|
+
/**
|
|
133
|
+
* Identifies the job type for routing and processing.
|
|
134
|
+
*/
|
|
135
|
+
kind: string;
|
|
136
|
+
/**
|
|
137
|
+
* Arbitrary job parameters, allowing for flexible job payloads.
|
|
138
|
+
* All values should be JSON-compatible.
|
|
139
|
+
*/
|
|
140
|
+
[key: string]: unknown;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Represents a job persisted in the database, including its state, metadata, and scheduling information.
|
|
145
|
+
*/
|
|
146
|
+
interface Job<T extends JobArgs = JobArgs> {
|
|
147
|
+
/**
|
|
148
|
+
* Unique job ID, generated by the database
|
|
149
|
+
*/
|
|
150
|
+
id: number;
|
|
151
|
+
/**
|
|
152
|
+
* Current state of the job (e.g., available, completed)
|
|
153
|
+
*/
|
|
154
|
+
state: JobState;
|
|
155
|
+
/**
|
|
156
|
+
* Current attempt number, incremented each time the job is worked
|
|
157
|
+
*/
|
|
158
|
+
attempt: number;
|
|
159
|
+
/**
|
|
160
|
+
* Maximum number of attempts before the job stops retrying
|
|
161
|
+
*/
|
|
162
|
+
maxAttempts: number;
|
|
163
|
+
/**
|
|
164
|
+
* Last time the job was worked, null if never
|
|
165
|
+
*/
|
|
166
|
+
attemptedAt: Date | null;
|
|
167
|
+
/**
|
|
168
|
+
* When the job record was created
|
|
169
|
+
*/
|
|
170
|
+
createdAt: Date;
|
|
171
|
+
/**
|
|
172
|
+
* When the job was finalized (completed or errored for last time), null if not finalized
|
|
173
|
+
*/
|
|
174
|
+
finalizedAt: Date | null;
|
|
175
|
+
/**
|
|
176
|
+
* When the job is scheduled to become available
|
|
177
|
+
*/
|
|
178
|
+
scheduledAt: Date;
|
|
179
|
+
/**
|
|
180
|
+
* Job priority (1 = highest, 4 = lowest)
|
|
181
|
+
*/
|
|
182
|
+
priority: number;
|
|
183
|
+
/**
|
|
184
|
+
* Job arguments, decoded from JSON
|
|
185
|
+
*/
|
|
186
|
+
args: T;
|
|
187
|
+
/**
|
|
188
|
+
* Worker IDs that have worked this job, null if never
|
|
189
|
+
*/
|
|
190
|
+
attemptedBy: string[] | null;
|
|
191
|
+
/**
|
|
192
|
+
* Errors for each attempt, ordered earliest to latest, null if none
|
|
193
|
+
*/
|
|
194
|
+
errors: AttemptError[] | null;
|
|
195
|
+
/**
|
|
196
|
+
* Job type identifier, set at insertion
|
|
197
|
+
*/
|
|
198
|
+
kind: string;
|
|
199
|
+
/**
|
|
200
|
+
* Arbitrary metadata associated with the job
|
|
201
|
+
*/
|
|
202
|
+
metadata: Record<string, unknown>;
|
|
203
|
+
/**
|
|
204
|
+
* Name of the queue where the job will be worked
|
|
205
|
+
*/
|
|
206
|
+
queue: string;
|
|
207
|
+
/**
|
|
208
|
+
* List of tags for grouping and categorizing jobs
|
|
209
|
+
*/
|
|
210
|
+
tags: string[];
|
|
211
|
+
/**
|
|
212
|
+
* Unique key for job within its kind, used for unique insertions, null if not set
|
|
213
|
+
*/
|
|
214
|
+
uniqueKey: Buffer | null;
|
|
215
|
+
/**
|
|
216
|
+
* States required for uniqueness, null if not set
|
|
217
|
+
*/
|
|
218
|
+
uniqueStates: JobState[] | null;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Result of a job insertion operation.
|
|
223
|
+
*
|
|
224
|
+
* - If a unique job already exists, `job` is the existing job and `skipped` is true.
|
|
225
|
+
* - If the job was inserted, `job` is the new job and `skipped` is false.
|
|
226
|
+
*/
|
|
227
|
+
interface InsertResult<T extends JobArgs = JobArgs> {
|
|
228
|
+
/**
|
|
229
|
+
* The inserted job, or the existing job if insertion was skipped due to uniqueness.
|
|
230
|
+
*/
|
|
231
|
+
job: Job<T>;
|
|
232
|
+
/**
|
|
233
|
+
* True if insertion was skipped because a unique job already exists.
|
|
234
|
+
*/
|
|
235
|
+
skipped: boolean;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export { type AttemptError as A, type InsertOpts as I, type JobArgs as J, type UniqueOpts as U, type InsertResult as a, type Job as b, JobState as c };
|