@odunlamizo/node-river 1.0.5 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/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 +22 -5
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/mappers.ts","../../../src/drivers/pg/pg-driver.ts"],"names":["query","values","result","row"],"mappings":";;;;;AAUO,IAAM,kBAAA,GAAqB,CAAC,OAAA,KAA8C;AAC/E,EAAA,IAAI,CAAC,OAAA,IAAW,OAAA,CAAQ,MAAA,KAAW,GAAG,OAAO,IAAA;AAE7C,EAAA,MAAM,SAAA,GAAwB;AAAA,IAAA,WAAA;AAAA;AAAA,IAAA,WAAA;AAAA;AAAA,IAAA,WAAA;AAAA;AAAA,IAAA,WAAA;AAAA;AAAA,IAAA,SAAA;AAAA;AAAA,IAAA,WAAA;AAAA;AAAA,IAAA,SAAA;AAAA;AAAA,IAAA,WAAA;AAAA;AAAA,GAS9B;AACA,EAAA,MAAM,IAAA,GAAO,QAAQ,CAAC,CAAA;AA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AM,KAAA,GAA6B;AACjC,IAAA,OAAO,IAAA,CAAK,KAAK,OAAA,EAAQ;AAAA,EAC3B;AAAA;AAAA;AAAA;AAAA,EAKQ,oBAAA,CACN,KACA,OAAA,EACiB;AACjB,IAAA,OAAO;AAAA,MACL,GAAA,EAAK;AAAA,QACH,GAAG,GAAA;AAAA,QACH,MAAM,EAAE,GAAG,IAAI,IAAA,EAAM,IAAA,EAAM,IAAI,IAAA,EAAK;AAAA,QACpC,YAAA,EAAc,kBAAA,CAAmB,GAAA,CAAI,YAAY;AAAA,OACnD;AAAA,MACA;AAAA,KACF;AAAA,EACF;AACF","file":"index.js","sourcesContent":["import { Buffer } from 'buffer';\nimport crypto from 'crypto';\nimport { InsertOpts, JobArgs, JobState } from '../types';\n\n/**\n * Converts a bit(8) Buffer to an array of JobState values using the bit order from river_job_state_in_bitmask.\n *\n * @param bitmask - The Buffer representing the job state bitmask.\n * @returns An array of JobState values corresponding to the set bits, or null if the bitmask is null.\n */\nexport const bitmaskToJobStates = (bitmask: Buffer | null): JobState[] | null => {\n if (!bitmask || bitmask.length === 0) return null;\n // Bit order: 7=available, 6=cancelled, 5=completed, 4=discarded, 3=pending, 2=retryable, 1=running, 0=scheduled\n const allStates: JobState[] = [\n JobState.Available, // 7\n JobState.Cancelled, // 6\n JobState.Completed, // 5\n JobState.Discarded, // 4\n JobState.Pending, // 3\n JobState.Retryable, // 2\n JobState.Running, // 1\n JobState.Scheduled, // 0\n ];\n const byte = bitmask[0];\n // Map bits 7..0 to allStates\n return allStates.filter((_, i) => (byte & (1 << (7 - i))) !== 0);\n};\n\n/**\n * Maps job args and unique options to a unique key buffer.\n *\n * @param args - The job arguments to use for uniqueness computation.\n * @param opts - The insertion options, including unique options.\n * @returns A Buffer containing the unique key, or undefined if no unique options are set.\n */\nexport const mapToUniqueKey = (args: JobArgs, opts: InsertOpts): Buffer | undefined => {\n const uniqueOpts = opts.uniqueOpts;\n if (!uniqueOpts) return undefined;\n\n const keyParts: Record<string, unknown> = {};\n\n if (!uniqueOpts.excludeKind) {\n keyParts.kind = args.kind;\n }\n\n if (uniqueOpts.byArgs === true) {\n keyParts.args = args;\n } else if (Array.isArray(uniqueOpts.byArgs)) {\n keyParts.args = Object.fromEntries(uniqueOpts.byArgs.sort().map((k) => [k, args[k]]));\n }\n\n if (uniqueOpts.byQueue) {\n keyParts.queue = opts.queue;\n }\n\n if (uniqueOpts.byPeriod && opts.scheduledAt) {\n const date = new Date(opts.scheduledAt);\n const period = uniqueOpts.byPeriod;\n const timestamp = Math.floor(date.getTime() / 1000);\n const rounded = timestamp - (timestamp % period);\n keyParts.period = rounded;\n }\n\n const hash = crypto.createHash('sha256').update(JSON.stringify(keyParts)).digest();\n\n return Buffer.from(hash);\n};\n","// RiverQueue driver implementation using the 'pg' library.\nimport { Buffer } from 'buffer';\nimport { Pool, PoolClient, PoolConfig } from 'pg';\nimport { InsertOpts, InsertResult, Job, JobArgs } from '../../types';\nimport { bitmaskToJobStates, mapToUniqueKey } from '../../utils';\nimport Driver from '../driver';\nimport Options from './pg-options';\n\n// Implements the RiverQueue Driver interface using the 'pg' library.\nexport default class PgDriver implements Driver<PoolClient> {\n private readonly pool: Pool;\n\n /**\n * Creates a new PgDriver instance.\n * @param options - Options for configuring the RiverQueue pg driver connection pool. Fields include:\n * - connectionString: Database connection string\n * - connectionTimeoutMillis: Optional, connection timeout in milliseconds\n * - idleTimeoutMillis: Optional, idle timeout in milliseconds\n * - max: Optional, maximum number of clients in the pool\n */\n constructor(options: Options) {\n const config: PoolConfig = { ...options };\n this.pool = new Pool(config);\n }\n\n async verifyConnection(): Promise<void> {\n try {\n const client = await this.pool.connect();\n try {\n await client.query('SELECT 1');\n } finally {\n client.release();\n }\n } catch (error) {\n throw new Error(\n `Database connection failed: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n }\n\n async close(): Promise<void> {\n await this.pool.end();\n }\n\n async insert<T extends JobArgs>(args: T, opts: InsertOpts): Promise<InsertResult<T>> {\n const client = await this.pool.connect();\n try {\n return await this.insertTx(client, args, opts);\n } finally {\n client.release();\n }\n }\n\n async insertTx<T extends JobArgs>(\n tx: PoolClient,\n args: T,\n opts: InsertOpts,\n ): Promise<InsertResult<T>> {\n if (!opts.queue) {\n throw new Error('Queue name is required in InsertOpts');\n }\n\n if (!opts.maxAttempts) {\n throw new Error('maxAttempts is required in InsertOpts');\n }\n\n let uniqueKey: Buffer | undefined;\n if (opts.uniqueOpts) {\n uniqueKey = mapToUniqueKey(args, opts);\n }\n\n if (uniqueKey) {\n const stateList = opts.uniqueOpts?.byState || [];\n\n let query = 'SELECT * FROM river_job WHERE unique_key = $1';\n let values: (Buffer | string[])[] = [uniqueKey];\n\n if (stateList.length > 0) {\n query += ' AND state = ANY($2)';\n values.push(stateList);\n }\n\n query += ' LIMIT 1';\n\n const result = await tx.query<Omit<Job, 'uniqueStates'> & { uniqueStates: Buffer | null }>(\n query,\n values,\n );\n\n if (result.rows.length > 0) {\n const row = result.rows[0];\n\n return this.mapRowToInsertResult(row, true);\n }\n }\n\n const { kind, ...restArgs } = args;\n const columns = ['kind', 'args', 'queue', 'max_attempts'];\n const values: (string | number | Buffer)[] = [\n kind,\n JSON.stringify(restArgs),\n opts.queue,\n opts.maxAttempts,\n ];\n\n if (opts.tags) {\n columns.push('tags');\n values.push(JSON.stringify(opts.tags));\n }\n\n if (opts.priority) {\n columns.push('priority');\n values.push(opts.priority);\n }\n\n if (opts.metadata) {\n columns.push('metadata');\n values.push(JSON.stringify(opts.metadata));\n }\n\n if (opts.scheduledAt) {\n columns.push('scheduled_at');\n values.push(\n opts.scheduledAt instanceof Date ? opts.scheduledAt.toISOString() : opts.scheduledAt,\n );\n }\n\n if (uniqueKey) {\n columns.push('unique_key');\n values.push(uniqueKey);\n }\n\n const placeholders = columns.map((_, i) => `$${i + 1}`);\n const query = `INSERT INTO river_job (${columns.join(', ')}) VALUES (${placeholders.join(', ')}) RETURNING\n id,\n state,\n attempt,\n max_attempts as \"maxAttempts\",\n attempted_at as \"attemptedAt\",\n created_at as \"createdAt\",\n finalized_at as \"finalizedAt\",\n scheduled_at as \"scheduledAt\",\n priority,\n args,\n attempted_by as \"attemptedBy\",\n errors,\n kind,\n metadata,\n queue,\n tags,\n unique_key as \"uniqueKey\",\n unique_states as \"uniqueStates\"`;\n const result = await tx.query<Omit<Job, 'uniqueStates'> & { uniqueStates: Buffer | null }>(\n query,\n values,\n );\n\n const row = result.rows[0];\n if (!row) return row;\n\n return this.mapRowToInsertResult(row, false);\n }\n\n async insertMany<T extends JobArgs>(\n jobs: { args: T; opts: InsertOpts }[],\n ): Promise<InsertResult<T>[]> {\n const client = await this.pool.connect();\n try {\n await client.query('BEGIN');\n\n const results: InsertResult<T>[] = [];\n for (const job of jobs) {\n results.push(await this.insertTx(client, job.args, job.opts));\n }\n\n await client.query('COMMIT');\n\n return results;\n } catch (error) {\n await client.query('ROLLBACK');\n\n throw error;\n } finally {\n client.release();\n }\n }\n\n async getTx(): Promise<PoolClient> {\n return this.pool.connect();\n }\n\n /**\n * Helper to map a DB row to a Job<T> and InsertResult.\n */\n private mapRowToInsertResult<T extends JobArgs>(\n row: Omit<Job, 'uniqueStates'> & { uniqueStates: Buffer | null },\n skipped: boolean,\n ): InsertResult<T> {\n return {\n job: {\n ...row,\n args: { ...row.args, kind: row.kind } as T,\n uniqueStates: bitmaskToJobStates(row.uniqueStates),\n },\n skipped,\n };\n }\n}\n"]}
|
package/dist/index.cjs
CHANGED
|
@@ -1,28 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
RiverClient: () => RiverClient
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(index_exports);
|
|
1
|
+
'use strict';
|
|
26
2
|
|
|
27
3
|
// src/client.ts
|
|
28
4
|
var RiverClient = class {
|
|
@@ -99,7 +75,7 @@ var RiverClient = class {
|
|
|
99
75
|
return this.driver.insertMany(jobsWithDefaults);
|
|
100
76
|
}
|
|
101
77
|
};
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
78
|
+
|
|
79
|
+
exports.RiverClient = RiverClient;
|
|
80
|
+
//# sourceMappingURL=index.cjs.map
|
|
81
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -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,GAA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AAW,gBAAgB,CAAA;AAAA,EAChD;AACF","file":"index.cjs","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"]}
|
package/dist/index.d.cts
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-vSyPLsFq.cjs';
|
|
2
|
+
import { ClientConfiguration } from './types.cjs';
|
|
3
|
+
import { J as JobArgs, I as InsertOpts, a as InsertResult } from './insert-result-Bf0bAFvJ.cjs';
|
|
4
|
+
import 'buffer';
|
|
302
5
|
|
|
303
6
|
/**
|
|
304
7
|
* Provides methods to enqueue jobs and manage queue operations.
|