@platformatic/job-queue 0.0.1 → 0.1.0-alpha.3
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 +511 -0
- package/dist/consumer.d.ts +43 -0
- package/dist/consumer.d.ts.map +1 -0
- package/dist/consumer.js +214 -0
- package/dist/consumer.js.map +1 -0
- package/dist/errors.d.ts +60 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +141 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/producer.d.ts +39 -0
- package/dist/producer.d.ts.map +1 -0
- package/dist/producer.js +163 -0
- package/dist/producer.js.map +1 -0
- package/dist/queue.d.ts +42 -0
- package/dist/queue.d.ts.map +1 -0
- package/dist/queue.js +153 -0
- package/dist/queue.js.map +1 -0
- package/dist/reaper.d.ts +52 -0
- package/dist/reaper.d.ts.map +1 -0
- package/dist/reaper.js +376 -0
- package/dist/reaper.js.map +1 -0
- package/dist/serde/index.d.ts +19 -0
- package/dist/serde/index.d.ts.map +1 -0
- package/dist/serde/index.js +18 -0
- package/dist/serde/index.js.map +1 -0
- package/dist/storage/file.d.ts +44 -0
- package/dist/storage/file.d.ts.map +1 -0
- package/dist/storage/file.js +601 -0
- package/dist/storage/file.js.map +1 -0
- package/dist/storage/memory.d.ts +39 -0
- package/dist/storage/memory.d.ts.map +1 -0
- package/dist/storage/memory.js +292 -0
- package/dist/storage/memory.js.map +1 -0
- package/dist/storage/redis.d.ts +47 -0
- package/dist/storage/redis.d.ts.map +1 -0
- package/dist/storage/redis.js +317 -0
- package/dist/storage/redis.js.map +1 -0
- package/dist/storage/types.d.ts +179 -0
- package/dist/storage/types.d.ts.map +1 -0
- package/dist/storage/types.js +2 -0
- package/dist/storage/types.js.map +1 -0
- package/dist/types.d.ts +126 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/id.d.ts +10 -0
- package/dist/utils/id.d.ts.map +1 -0
- package/dist/utils/id.js +18 -0
- package/dist/utils/id.js.map +1 -0
- package/dist/utils/state.d.ts +13 -0
- package/dist/utils/state.d.ts.map +1 -0
- package/dist/utils/state.js +22 -0
- package/dist/utils/state.js.map +1 -0
- package/package.json +45 -9
package/dist/consumer.js
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import { EventEmitter } from 'node:events';
|
|
2
|
+
import { MaxRetriesError } from "./errors.js";
|
|
3
|
+
import { createJsonSerde } from "./serde/index.js";
|
|
4
|
+
/**
|
|
5
|
+
* Consumer handles processing jobs from the queue
|
|
6
|
+
*/
|
|
7
|
+
export class Consumer extends EventEmitter {
|
|
8
|
+
#storage;
|
|
9
|
+
#workerId;
|
|
10
|
+
#payloadSerde;
|
|
11
|
+
#resultSerde;
|
|
12
|
+
#concurrency;
|
|
13
|
+
#blockTimeout;
|
|
14
|
+
#maxRetries;
|
|
15
|
+
#resultTTL;
|
|
16
|
+
#visibilityTimeout;
|
|
17
|
+
#handler = null;
|
|
18
|
+
#running = false;
|
|
19
|
+
#activeJobs = 0;
|
|
20
|
+
#abortController = null;
|
|
21
|
+
#jobAbortControllers = new Map();
|
|
22
|
+
constructor(config) {
|
|
23
|
+
super();
|
|
24
|
+
this.#storage = config.storage;
|
|
25
|
+
this.#workerId = config.workerId;
|
|
26
|
+
this.#payloadSerde = config.payloadSerde ?? createJsonSerde();
|
|
27
|
+
this.#resultSerde = config.resultSerde ?? createJsonSerde();
|
|
28
|
+
this.#concurrency = config.concurrency ?? 1;
|
|
29
|
+
this.#blockTimeout = config.blockTimeout ?? 5;
|
|
30
|
+
this.#maxRetries = config.maxRetries ?? 3;
|
|
31
|
+
this.#resultTTL = config.resultTTL ?? 3600000;
|
|
32
|
+
this.#visibilityTimeout = config.visibilityTimeout ?? 30000;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Register a job handler
|
|
36
|
+
*/
|
|
37
|
+
execute(handler) {
|
|
38
|
+
this.#handler = handler;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Start consuming jobs
|
|
42
|
+
*/
|
|
43
|
+
async start() {
|
|
44
|
+
if (this.#running)
|
|
45
|
+
return;
|
|
46
|
+
if (!this.#handler) {
|
|
47
|
+
throw new Error('No handler registered. Call execute() first.');
|
|
48
|
+
}
|
|
49
|
+
this.#running = true;
|
|
50
|
+
this.#abortController = new AbortController();
|
|
51
|
+
// Register worker
|
|
52
|
+
await this.#storage.registerWorker(this.#workerId, this.#visibilityTimeout * 2);
|
|
53
|
+
// Start worker loops based on concurrency
|
|
54
|
+
const loops = [];
|
|
55
|
+
for (let i = 0; i < this.#concurrency; i++) {
|
|
56
|
+
loops.push(this.#workerLoop());
|
|
57
|
+
}
|
|
58
|
+
// Don't await - let them run in background
|
|
59
|
+
Promise.all(loops).catch((err) => {
|
|
60
|
+
this.emit('error', err);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Stop consuming jobs gracefully
|
|
65
|
+
*/
|
|
66
|
+
async stop() {
|
|
67
|
+
if (!this.#running)
|
|
68
|
+
return;
|
|
69
|
+
this.#running = false;
|
|
70
|
+
// Signal abort to worker loops
|
|
71
|
+
if (this.#abortController) {
|
|
72
|
+
this.#abortController.abort();
|
|
73
|
+
}
|
|
74
|
+
// Wait for active jobs to complete (with timeout)
|
|
75
|
+
const maxWait = this.#visibilityTimeout;
|
|
76
|
+
const startTime = Date.now();
|
|
77
|
+
while (this.#activeJobs > 0 && (Date.now() - startTime) < maxWait) {
|
|
78
|
+
await new Promise(resolve => setTimeout(resolve, 100));
|
|
79
|
+
}
|
|
80
|
+
// Abort any remaining jobs
|
|
81
|
+
for (const [, controller] of this.#jobAbortControllers) {
|
|
82
|
+
controller.abort();
|
|
83
|
+
}
|
|
84
|
+
this.#jobAbortControllers.clear();
|
|
85
|
+
// Unregister worker
|
|
86
|
+
await this.#storage.unregisterWorker(this.#workerId);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Worker loop that continuously dequeues and processes jobs
|
|
90
|
+
*/
|
|
91
|
+
async #workerLoop() {
|
|
92
|
+
while (this.#running) {
|
|
93
|
+
try {
|
|
94
|
+
const message = await this.#storage.dequeue(this.#workerId, this.#blockTimeout);
|
|
95
|
+
if (!message) {
|
|
96
|
+
// Timeout, check if still running
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
// Check if aborted
|
|
100
|
+
if (this.#abortController?.signal.aborted) {
|
|
101
|
+
// Put message back
|
|
102
|
+
const queueMessage = this.#deserializeMessage(message);
|
|
103
|
+
await this.#storage.requeue(queueMessage.id, message, this.#workerId);
|
|
104
|
+
this.emit('requeued', queueMessage.id);
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
// Process the job
|
|
108
|
+
await this.#processJob(message);
|
|
109
|
+
}
|
|
110
|
+
catch (err) {
|
|
111
|
+
if (!this.#running)
|
|
112
|
+
break;
|
|
113
|
+
this.emit('error', err);
|
|
114
|
+
// Brief pause before retrying loop
|
|
115
|
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Process a single job
|
|
121
|
+
*/
|
|
122
|
+
async #processJob(message) {
|
|
123
|
+
const queueMessage = this.#deserializeMessage(message);
|
|
124
|
+
const { id, payload, attempts, maxAttempts } = queueMessage;
|
|
125
|
+
// Check if job was cancelled (deleted from jobs hash)
|
|
126
|
+
const state = await this.#storage.getJobState(id);
|
|
127
|
+
if (!state) {
|
|
128
|
+
// Job was cancelled, just ack it
|
|
129
|
+
await this.#storage.ack(id, message, this.#workerId);
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
this.#activeJobs++;
|
|
133
|
+
// Create abort controller for this job
|
|
134
|
+
const jobAbortController = new AbortController();
|
|
135
|
+
this.#jobAbortControllers.set(id, jobAbortController);
|
|
136
|
+
// Set up visibility timeout
|
|
137
|
+
const visibilityTimer = setTimeout(() => {
|
|
138
|
+
jobAbortController.abort();
|
|
139
|
+
}, this.#visibilityTimeout);
|
|
140
|
+
// Update state to processing
|
|
141
|
+
const timestamp = Date.now();
|
|
142
|
+
await this.#storage.setJobState(id, `processing:${timestamp}:${this.#workerId}`);
|
|
143
|
+
await this.#storage.publishEvent(id, 'processing');
|
|
144
|
+
try {
|
|
145
|
+
const job = {
|
|
146
|
+
id,
|
|
147
|
+
payload,
|
|
148
|
+
attempts: attempts + 1,
|
|
149
|
+
signal: jobAbortController.signal
|
|
150
|
+
};
|
|
151
|
+
const result = await this.#executeHandler(job);
|
|
152
|
+
// Clear visibility timer
|
|
153
|
+
clearTimeout(visibilityTimer);
|
|
154
|
+
// Complete the job
|
|
155
|
+
const serializedResult = this.#resultSerde.serialize(result);
|
|
156
|
+
await this.#storage.completeJob(id, message, this.#workerId, serializedResult, this.#resultTTL);
|
|
157
|
+
this.emit('completed', id, result);
|
|
158
|
+
}
|
|
159
|
+
catch (err) {
|
|
160
|
+
// Clear visibility timer
|
|
161
|
+
clearTimeout(visibilityTimer);
|
|
162
|
+
const error = err;
|
|
163
|
+
const currentAttempts = attempts + 1;
|
|
164
|
+
if (currentAttempts < maxAttempts) {
|
|
165
|
+
// Retry - update message with incremented attempts
|
|
166
|
+
const updatedMessage = {
|
|
167
|
+
...queueMessage,
|
|
168
|
+
attempts: currentAttempts
|
|
169
|
+
};
|
|
170
|
+
const serializedMessage = this.#payloadSerde.serialize(updatedMessage);
|
|
171
|
+
await this.#storage.retryJob(id, serializedMessage, this.#workerId, currentAttempts);
|
|
172
|
+
this.emit('failing', id, error, currentAttempts);
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
// Max retries exceeded - fail the job
|
|
176
|
+
const maxRetriesError = new MaxRetriesError(id, currentAttempts, error);
|
|
177
|
+
const serializedError = Buffer.from(JSON.stringify({
|
|
178
|
+
message: error.message,
|
|
179
|
+
code: error.code,
|
|
180
|
+
stack: error.stack
|
|
181
|
+
}));
|
|
182
|
+
await this.#storage.failJob(id, message, this.#workerId, serializedError, this.#resultTTL);
|
|
183
|
+
this.emit('failed', id, maxRetriesError);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
finally {
|
|
187
|
+
this.#jobAbortControllers.delete(id);
|
|
188
|
+
this.#activeJobs--;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Execute the job handler (supports both async and callback styles)
|
|
193
|
+
*/
|
|
194
|
+
async #executeHandler(job) {
|
|
195
|
+
const handler = this.#handler;
|
|
196
|
+
// Check if callback style (handler.length > 1)
|
|
197
|
+
if (handler.length > 1) {
|
|
198
|
+
return new Promise((resolve, reject) => {
|
|
199
|
+
handler(job, (err, result) => {
|
|
200
|
+
if (err)
|
|
201
|
+
reject(err);
|
|
202
|
+
else
|
|
203
|
+
resolve(result);
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
// Async style
|
|
208
|
+
return handler(job);
|
|
209
|
+
}
|
|
210
|
+
#deserializeMessage(message) {
|
|
211
|
+
return this.#payloadSerde.deserialize(message);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
//# sourceMappingURL=consumer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consumer.js","sourceRoot":"","sources":["../src/consumer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAI1C,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAsBlD;;GAEG;AACH,MAAM,OAAO,QAA4B,SAAQ,YAAqC;IACpF,QAAQ,CAAS;IACjB,SAAS,CAAQ;IACjB,aAAa,CAAiB;IAC9B,YAAY,CAAgB;IAC5B,YAAY,CAA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a,CAAC,WAAW,CAAC,OAAO,CAAsC,CAAA;IACrF,CAAC;CACF"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base error for job queue errors
|
|
3
|
+
*/
|
|
4
|
+
export declare class JobQueueError extends Error {
|
|
5
|
+
code: string;
|
|
6
|
+
constructor(message: string, code: string);
|
|
7
|
+
toJSON(): Record<string, unknown>;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Timeout waiting for job result
|
|
11
|
+
*/
|
|
12
|
+
export declare class TimeoutError extends JobQueueError {
|
|
13
|
+
jobId: string;
|
|
14
|
+
constructor(jobId: string, timeout: number);
|
|
15
|
+
toJSON(): Record<string, unknown>;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Job failed after max retries
|
|
19
|
+
*/
|
|
20
|
+
export declare class MaxRetriesError extends JobQueueError {
|
|
21
|
+
jobId: string;
|
|
22
|
+
attempts: number;
|
|
23
|
+
lastError: Error;
|
|
24
|
+
constructor(jobId: string, attempts: number, lastError: Error);
|
|
25
|
+
toJSON(): Record<string, unknown>;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Job not found
|
|
29
|
+
*/
|
|
30
|
+
export declare class JobNotFoundError extends JobQueueError {
|
|
31
|
+
jobId: string;
|
|
32
|
+
constructor(jobId: string);
|
|
33
|
+
toJSON(): Record<string, unknown>;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Storage operation failed
|
|
37
|
+
*/
|
|
38
|
+
export declare class StorageError extends JobQueueError {
|
|
39
|
+
cause?: Error;
|
|
40
|
+
constructor(message: string, cause?: Error);
|
|
41
|
+
toJSON(): Record<string, unknown>;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Job was cancelled
|
|
45
|
+
*/
|
|
46
|
+
export declare class JobCancelledError extends JobQueueError {
|
|
47
|
+
jobId: string;
|
|
48
|
+
constructor(jobId: string);
|
|
49
|
+
toJSON(): Record<string, unknown>;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Job failed
|
|
53
|
+
*/
|
|
54
|
+
export declare class JobFailedError extends JobQueueError {
|
|
55
|
+
jobId: string;
|
|
56
|
+
originalError: string;
|
|
57
|
+
constructor(jobId: string, errorMessage: string);
|
|
58
|
+
toJSON(): Record<string, unknown>;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,aAAc,SAAQ,KAAK;IACtC,IAAI,EAAE,MAAM,CAAA;gBAEC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;IAO1C,MAAM,IAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAQnC;AAED;;GAEG;AACH,qBAAa,YAAa,SAAQ,aAAa;IAC7C,KAAK,EAAE,MAAM,CAAA;gBAEA,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IAM3C,MAAM,IAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAMnC;AAED;;GAEG;AACH,qBAAa,eAAgB,SAAQ,aAAa;IAChD,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;IAChB,SAAS,EAAE,KAAK,CAAA;gBAEH,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK;IAQ9D,MAAM,IAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAYnC;AAED;;GAEG;AACH,qBAAa,gBAAiB,SAAQ,aAAa;IACjD,KAAK,EAAE,MAAM,CAAA;gBAEA,KAAK,EAAE,MAAM;IAM1B,MAAM,IAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAMnC;AAED;;GAEG;AACH,qBAAa,YAAa,SAAQ,aAAa;IACpC,KAAK,CAAC,EAAE,KAAK,CAAA;gBAET,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK;IAM3C,MAAM,IAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAWnC;AAED;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,aAAa;IAClD,KAAK,EAAE,MAAM,CAAA;gBAEA,KAAK,EAAE,MAAM;IAM1B,MAAM,IAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAMnC;AAED;;GAEG;AACH,qBAAa,cAAe,SAAQ,aAAa;IAC/C,KAAK,EAAE,MAAM,CAAA;IACb,aAAa,EAAE,MAAM,CAAA;gBAER,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM;IAOhD,MAAM,IAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAOnC"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base error for job queue errors
|
|
3
|
+
*/
|
|
4
|
+
export class JobQueueError extends Error {
|
|
5
|
+
code;
|
|
6
|
+
constructor(message, code) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.name = 'JobQueueError';
|
|
9
|
+
this.code = code;
|
|
10
|
+
Error.captureStackTrace(this, this.constructor);
|
|
11
|
+
}
|
|
12
|
+
toJSON() {
|
|
13
|
+
return {
|
|
14
|
+
name: this.name,
|
|
15
|
+
message: this.message,
|
|
16
|
+
code: this.code,
|
|
17
|
+
stack: this.stack
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Timeout waiting for job result
|
|
23
|
+
*/
|
|
24
|
+
export class TimeoutError extends JobQueueError {
|
|
25
|
+
jobId;
|
|
26
|
+
constructor(jobId, timeout) {
|
|
27
|
+
super(`Job '${jobId}' timed out after ${timeout}ms`, 'TIMEOUT');
|
|
28
|
+
this.name = 'TimeoutError';
|
|
29
|
+
this.jobId = jobId;
|
|
30
|
+
}
|
|
31
|
+
toJSON() {
|
|
32
|
+
return {
|
|
33
|
+
...super.toJSON(),
|
|
34
|
+
jobId: this.jobId
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Job failed after max retries
|
|
40
|
+
*/
|
|
41
|
+
export class MaxRetriesError extends JobQueueError {
|
|
42
|
+
jobId;
|
|
43
|
+
attempts;
|
|
44
|
+
lastError;
|
|
45
|
+
constructor(jobId, attempts, lastError) {
|
|
46
|
+
super(`Job '${jobId}' failed after ${attempts} attempts: ${lastError.message}`, 'MAX_RETRIES');
|
|
47
|
+
this.name = 'MaxRetriesError';
|
|
48
|
+
this.jobId = jobId;
|
|
49
|
+
this.attempts = attempts;
|
|
50
|
+
this.lastError = lastError;
|
|
51
|
+
}
|
|
52
|
+
toJSON() {
|
|
53
|
+
return {
|
|
54
|
+
...super.toJSON(),
|
|
55
|
+
jobId: this.jobId,
|
|
56
|
+
attempts: this.attempts,
|
|
57
|
+
lastError: {
|
|
58
|
+
name: this.lastError.name,
|
|
59
|
+
message: this.lastError.message,
|
|
60
|
+
stack: this.lastError.stack
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Job not found
|
|
67
|
+
*/
|
|
68
|
+
export class JobNotFoundError extends JobQueueError {
|
|
69
|
+
jobId;
|
|
70
|
+
constructor(jobId) {
|
|
71
|
+
super(`Job '${jobId}' not found`, 'JOB_NOT_FOUND');
|
|
72
|
+
this.name = 'JobNotFoundError';
|
|
73
|
+
this.jobId = jobId;
|
|
74
|
+
}
|
|
75
|
+
toJSON() {
|
|
76
|
+
return {
|
|
77
|
+
...super.toJSON(),
|
|
78
|
+
jobId: this.jobId
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Storage operation failed
|
|
84
|
+
*/
|
|
85
|
+
export class StorageError extends JobQueueError {
|
|
86
|
+
cause;
|
|
87
|
+
constructor(message, cause) {
|
|
88
|
+
super(message, 'STORAGE_ERROR');
|
|
89
|
+
this.name = 'StorageError';
|
|
90
|
+
this.cause = cause;
|
|
91
|
+
}
|
|
92
|
+
toJSON() {
|
|
93
|
+
const json = { ...super.toJSON() };
|
|
94
|
+
if (this.cause) {
|
|
95
|
+
json.cause = {
|
|
96
|
+
name: this.cause.name,
|
|
97
|
+
message: this.cause.message,
|
|
98
|
+
stack: this.cause.stack
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
return json;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Job was cancelled
|
|
106
|
+
*/
|
|
107
|
+
export class JobCancelledError extends JobQueueError {
|
|
108
|
+
jobId;
|
|
109
|
+
constructor(jobId) {
|
|
110
|
+
super(`Job '${jobId}' was cancelled`, 'JOB_CANCELLED');
|
|
111
|
+
this.name = 'JobCancelledError';
|
|
112
|
+
this.jobId = jobId;
|
|
113
|
+
}
|
|
114
|
+
toJSON() {
|
|
115
|
+
return {
|
|
116
|
+
...super.toJSON(),
|
|
117
|
+
jobId: this.jobId
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Job failed
|
|
123
|
+
*/
|
|
124
|
+
export class JobFailedError extends JobQueueError {
|
|
125
|
+
jobId;
|
|
126
|
+
originalError;
|
|
127
|
+
constructor(jobId, errorMessage) {
|
|
128
|
+
super(`Job '${jobId}' failed: ${errorMessage}`, 'JOB_FAILED');
|
|
129
|
+
this.name = 'JobFailedError';
|
|
130
|
+
this.jobId = jobId;
|
|
131
|
+
this.originalError = errorMessage;
|
|
132
|
+
}
|
|
133
|
+
toJSON() {
|
|
134
|
+
return {
|
|
135
|
+
...super.toJSON(),
|
|
136
|
+
jobId: this.jobId,
|
|
137
|
+
originalError: this.originalError
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140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@@
|
|
|
1
|
+
export type { QueueMessage, MessageState, MessageStatus, EnqueueOptions, EnqueueAndWaitOptions, EnqueueResult, CancelResult, Job, JobHandler, QueueConfig, QueueEvents } from './types.ts';
|
|
2
|
+
export { JobQueueError, TimeoutError, MaxRetriesError, JobNotFoundError, StorageError, JobCancelledError, JobFailedError } from './errors.ts';
|
|
3
|
+
export type { Serde } from './serde/index.ts';
|
|
4
|
+
export { JsonSerde, createJsonSerde } from './serde/index.ts';
|
|
5
|
+
export type { Storage } from './storage/types.ts';
|
|
6
|
+
export { MemoryStorage } from './storage/memory.ts';
|
|
7
|
+
export { RedisStorage } from './storage/redis.ts';
|
|
8
|
+
export { FileStorage } from './storage/file.ts';
|
|
9
|
+
export { Queue } from './queue.ts';
|
|
10
|
+
export { Reaper } from './reaper.ts';
|
|
11
|
+
export { generateId, contentId } from './utils/id.ts';
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,YAAY,EACV,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,cAAc,EACd,qBAAqB,EACrB,aAAa,EACb,YAAY,EACZ,GAAG,EACH,UAAU,EACV,WAAW,EACX,WAAW,EACZ,MAAM,YAAY,CAAA;AAGnB,OAAO,EACL,aAAa,EACb,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,YAAY,EACZ,iBAAiB,EACjB,cAAc,EACf,MAAM,aAAa,CAAA;AAGpB,YAAY,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAG7D,YAAY,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAG/C,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAGlC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAGpC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Errors
|
|
2
|
+
export { JobQueueError, TimeoutError, MaxRetriesError, JobNotFoundError, StorageError, JobCancelledError, JobFailedError } from "./errors.js";
|
|
3
|
+
export { JsonSerde, createJsonSerde } from "./serde/index.js";
|
|
4
|
+
export { MemoryStorage } from "./storage/memory.js";
|
|
5
|
+
export { RedisStorage } from "./storage/redis.js";
|
|
6
|
+
export { FileStorage } from "./storage/file.js";
|
|
7
|
+
// Queue
|
|
8
|
+
export { Queue } from "./queue.js";
|
|
9
|
+
// Reaper
|
|
10
|
+
export { Reaper } from "./reaper.js";
|
|
11
|
+
// Utils
|
|
12
|
+
export { generateId, contentId } from "./utils/id.js";
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAeA,SAAS;AACT,OAAO,EACL,aAAa,EACb,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,YAAY,EACZ,iBAAiB,EACjB,cAAc,EACf,MAAM,aAAa,CAAA;AAIpB,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAI7D,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAE/C,QAAQ;AACR,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAElC,SAAS;AACT,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEpC,QAAQ;AACR,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { Storage } from './storage/types.ts';
|
|
2
|
+
import type { Serde } from './serde/index.ts';
|
|
3
|
+
import type { EnqueueOptions, EnqueueAndWaitOptions, EnqueueResult, CancelResult, MessageStatus } from './types.ts';
|
|
4
|
+
interface ProducerConfig<TPayload, TResult> {
|
|
5
|
+
storage: Storage;
|
|
6
|
+
payloadSerde?: Serde<TPayload>;
|
|
7
|
+
resultSerde?: Serde<TResult>;
|
|
8
|
+
maxRetries?: number;
|
|
9
|
+
resultTTL?: number;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Producer handles enqueueing jobs and retrieving results
|
|
13
|
+
*/
|
|
14
|
+
export declare class Producer<TPayload, TResult> {
|
|
15
|
+
#private;
|
|
16
|
+
constructor(config: ProducerConfig<TPayload, TResult>);
|
|
17
|
+
/**
|
|
18
|
+
* Enqueue a job (fire-and-forget)
|
|
19
|
+
*/
|
|
20
|
+
enqueue(id: string, payload: TPayload, options?: EnqueueOptions): Promise<EnqueueResult<TResult>>;
|
|
21
|
+
/**
|
|
22
|
+
* Enqueue a job and wait for the result
|
|
23
|
+
*/
|
|
24
|
+
enqueueAndWait(id: string, payload: TPayload, options?: EnqueueAndWaitOptions): Promise<TResult>;
|
|
25
|
+
/**
|
|
26
|
+
* Cancel a pending job
|
|
27
|
+
*/
|
|
28
|
+
cancel(id: string): Promise<CancelResult>;
|
|
29
|
+
/**
|
|
30
|
+
* Get the result of a completed job
|
|
31
|
+
*/
|
|
32
|
+
getResult(id: string): Promise<TResult | null>;
|
|
33
|
+
/**
|
|
34
|
+
* Get the status of a job
|
|
35
|
+
*/
|
|
36
|
+
getStatus(id: string): Promise<MessageStatus<TResult> | null>;
|
|
37
|
+
}
|
|
38
|
+
export {};
|
|
39
|
+
//# sourceMappingURL=produc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