@trigger.dev/redis-worker 4.0.0-v4-beta.24 → 4.0.0-v4-beta.25
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/index.cjs +44 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -2
- package/dist/index.d.ts +14 -2
- package/dist/index.js +44 -5
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -40,13 +40,15 @@ declare class SimpleQueue<TMessageCatalog extends MessageCatalogSchema> {
|
|
|
40
40
|
redisOptions: RedisOptions;
|
|
41
41
|
logger?: Logger;
|
|
42
42
|
});
|
|
43
|
-
|
|
43
|
+
cancel(cancellationKey: string): Promise<void>;
|
|
44
|
+
enqueue({ id, job, item, attempt, availableAt, visibilityTimeoutMs, cancellationKey, }: {
|
|
44
45
|
id?: string;
|
|
45
46
|
job: MessageCatalogKey<TMessageCatalog>;
|
|
46
47
|
item: MessageCatalogValue<TMessageCatalog, MessageCatalogKey<TMessageCatalog>>;
|
|
47
48
|
attempt?: number;
|
|
48
49
|
availableAt?: Date;
|
|
49
50
|
visibilityTimeoutMs: number;
|
|
51
|
+
cancellationKey?: string;
|
|
50
52
|
}): Promise<void>;
|
|
51
53
|
enqueueOnce({ id, job, item, attempt, availableAt, visibilityTimeoutMs, }: {
|
|
52
54
|
id: string;
|
|
@@ -71,6 +73,7 @@ declare class SimpleQueue<TMessageCatalog extends MessageCatalogSchema> {
|
|
|
71
73
|
declare module "@internal/redis" {
|
|
72
74
|
interface RedisCommander<Context> {
|
|
73
75
|
enqueueItem(queue: string, items: string, id: string, score: number, serializedItem: string, callback?: Callback<number>): Result<number, Context>;
|
|
76
|
+
enqueueItemWithCancellationKey(queue: string, items: string, cancellationKey: string, id: string, score: number, serializedItem: string, callback?: Callback<number>): Result<number, Context>;
|
|
74
77
|
dequeueItems(queue: string, items: string, now: number, count: number, callback?: Callback<Array<[string, string, string]>>): Result<Array<[string, string, string]>, Context>;
|
|
75
78
|
ackItem(queue: string, items: string, id: string, deduplicationKey: string, callback?: Callback<number>): Result<number, Context>;
|
|
76
79
|
redriveFromDeadLetterQueue(queue: string, items: string, dlq: string, dlqItems: string, id: string, callback?: Callback<number>): Result<number, Context>;
|
|
@@ -161,12 +164,13 @@ declare class Worker<TCatalog extends WorkerCatalog> {
|
|
|
161
164
|
* @param options.availableAt - Optional date when the job should become available for processing. Defaults to now.
|
|
162
165
|
* @returns A promise that resolves when the job is enqueued.
|
|
163
166
|
*/
|
|
164
|
-
enqueue<K extends keyof TCatalog>({ id, job, payload, visibilityTimeoutMs, availableAt, }: {
|
|
167
|
+
enqueue<K extends keyof TCatalog>({ id, job, payload, visibilityTimeoutMs, availableAt, cancellationKey, }: {
|
|
165
168
|
id?: string;
|
|
166
169
|
job: K;
|
|
167
170
|
payload: z.infer<TCatalog[K]["schema"]>;
|
|
168
171
|
visibilityTimeoutMs?: number;
|
|
169
172
|
availableAt?: Date;
|
|
173
|
+
cancellationKey?: string;
|
|
170
174
|
}): Promise<void>;
|
|
171
175
|
/**
|
|
172
176
|
* Enqueues a job for processing once. If the job is already in the queue, it will be ignored.
|
|
@@ -190,6 +194,14 @@ declare class Worker<TCatalog extends WorkerCatalog> {
|
|
|
190
194
|
* If the job isn't in the queue, it will be ignored.
|
|
191
195
|
*/
|
|
192
196
|
reschedule(id: string, availableAt: Date): Promise<void>;
|
|
197
|
+
/**
|
|
198
|
+
* Cancels a job before it's enqueued.
|
|
199
|
+
* @param cancellationKey - The cancellation key to cancel.
|
|
200
|
+
* @returns A promise that resolves when the job is cancelled.
|
|
201
|
+
*
|
|
202
|
+
* Any jobs enqueued with the same cancellation key will be not be enqueued.
|
|
203
|
+
*/
|
|
204
|
+
cancel(cancellationKey: string): Promise<void>;
|
|
193
205
|
ack(id: string): Promise<void>;
|
|
194
206
|
getJob(id: string): Promise<QueueItem<QueueCatalogFromWorkerCatalog<TCatalog>> | null>;
|
|
195
207
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -40,13 +40,15 @@ declare class SimpleQueue<TMessageCatalog extends MessageCatalogSchema> {
|
|
|
40
40
|
redisOptions: RedisOptions;
|
|
41
41
|
logger?: Logger;
|
|
42
42
|
});
|
|
43
|
-
|
|
43
|
+
cancel(cancellationKey: string): Promise<void>;
|
|
44
|
+
enqueue({ id, job, item, attempt, availableAt, visibilityTimeoutMs, cancellationKey, }: {
|
|
44
45
|
id?: string;
|
|
45
46
|
job: MessageCatalogKey<TMessageCatalog>;
|
|
46
47
|
item: MessageCatalogValue<TMessageCatalog, MessageCatalogKey<TMessageCatalog>>;
|
|
47
48
|
attempt?: number;
|
|
48
49
|
availableAt?: Date;
|
|
49
50
|
visibilityTimeoutMs: number;
|
|
51
|
+
cancellationKey?: string;
|
|
50
52
|
}): Promise<void>;
|
|
51
53
|
enqueueOnce({ id, job, item, attempt, availableAt, visibilityTimeoutMs, }: {
|
|
52
54
|
id: string;
|
|
@@ -71,6 +73,7 @@ declare class SimpleQueue<TMessageCatalog extends MessageCatalogSchema> {
|
|
|
71
73
|
declare module "@internal/redis" {
|
|
72
74
|
interface RedisCommander<Context> {
|
|
73
75
|
enqueueItem(queue: string, items: string, id: string, score: number, serializedItem: string, callback?: Callback<number>): Result<number, Context>;
|
|
76
|
+
enqueueItemWithCancellationKey(queue: string, items: string, cancellationKey: string, id: string, score: number, serializedItem: string, callback?: Callback<number>): Result<number, Context>;
|
|
74
77
|
dequeueItems(queue: string, items: string, now: number, count: number, callback?: Callback<Array<[string, string, string]>>): Result<Array<[string, string, string]>, Context>;
|
|
75
78
|
ackItem(queue: string, items: string, id: string, deduplicationKey: string, callback?: Callback<number>): Result<number, Context>;
|
|
76
79
|
redriveFromDeadLetterQueue(queue: string, items: string, dlq: string, dlqItems: string, id: string, callback?: Callback<number>): Result<number, Context>;
|
|
@@ -161,12 +164,13 @@ declare class Worker<TCatalog extends WorkerCatalog> {
|
|
|
161
164
|
* @param options.availableAt - Optional date when the job should become available for processing. Defaults to now.
|
|
162
165
|
* @returns A promise that resolves when the job is enqueued.
|
|
163
166
|
*/
|
|
164
|
-
enqueue<K extends keyof TCatalog>({ id, job, payload, visibilityTimeoutMs, availableAt, }: {
|
|
167
|
+
enqueue<K extends keyof TCatalog>({ id, job, payload, visibilityTimeoutMs, availableAt, cancellationKey, }: {
|
|
165
168
|
id?: string;
|
|
166
169
|
job: K;
|
|
167
170
|
payload: z.infer<TCatalog[K]["schema"]>;
|
|
168
171
|
visibilityTimeoutMs?: number;
|
|
169
172
|
availableAt?: Date;
|
|
173
|
+
cancellationKey?: string;
|
|
170
174
|
}): Promise<void>;
|
|
171
175
|
/**
|
|
172
176
|
* Enqueues a job for processing once. If the job is already in the queue, it will be ignored.
|
|
@@ -190,6 +194,14 @@ declare class Worker<TCatalog extends WorkerCatalog> {
|
|
|
190
194
|
* If the job isn't in the queue, it will be ignored.
|
|
191
195
|
*/
|
|
192
196
|
reschedule(id: string, availableAt: Date): Promise<void>;
|
|
197
|
+
/**
|
|
198
|
+
* Cancels a job before it's enqueued.
|
|
199
|
+
* @param cancellationKey - The cancellation key to cancel.
|
|
200
|
+
* @returns A promise that resolves when the job is cancelled.
|
|
201
|
+
*
|
|
202
|
+
* Any jobs enqueued with the same cancellation key will be not be enqueued.
|
|
203
|
+
*/
|
|
204
|
+
cancel(cancellationKey: string): Promise<void>;
|
|
193
205
|
ack(id: string): Promise<void>;
|
|
194
206
|
getJob(id: string): Promise<QueueItem<QueueCatalogFromWorkerCatalog<TCatalog>> | null>;
|
|
195
207
|
/**
|
package/dist/index.js
CHANGED
|
@@ -9466,13 +9466,17 @@ var SimpleQueue = class {
|
|
|
9466
9466
|
this.#registerCommands();
|
|
9467
9467
|
this.schema = schema;
|
|
9468
9468
|
}
|
|
9469
|
+
async cancel(cancellationKey) {
|
|
9470
|
+
await this.redis.set(`cancellationKey:${cancellationKey}`, "1", "EX", 60 * 60 * 24);
|
|
9471
|
+
}
|
|
9469
9472
|
async enqueue({
|
|
9470
9473
|
id,
|
|
9471
9474
|
job,
|
|
9472
9475
|
item,
|
|
9473
9476
|
attempt,
|
|
9474
9477
|
availableAt,
|
|
9475
|
-
visibilityTimeoutMs
|
|
9478
|
+
visibilityTimeoutMs,
|
|
9479
|
+
cancellationKey
|
|
9476
9480
|
}) {
|
|
9477
9481
|
try {
|
|
9478
9482
|
const score = availableAt ? availableAt.getTime() : Date.now();
|
|
@@ -9484,13 +9488,14 @@ var SimpleQueue = class {
|
|
|
9484
9488
|
attempt,
|
|
9485
9489
|
deduplicationKey
|
|
9486
9490
|
});
|
|
9487
|
-
const result = await this.redis.
|
|
9491
|
+
const result = cancellationKey ? await this.redis.enqueueItemWithCancellationKey(
|
|
9488
9492
|
`queue`,
|
|
9489
9493
|
`items`,
|
|
9494
|
+
`cancellationKey:${cancellationKey}`,
|
|
9490
9495
|
id ?? nanoid(),
|
|
9491
9496
|
score,
|
|
9492
9497
|
serializedItem
|
|
9493
|
-
);
|
|
9498
|
+
) : await this.redis.enqueueItem(`queue`, `items`, id ?? nanoid(), score, serializedItem);
|
|
9494
9499
|
if (result !== 1) {
|
|
9495
9500
|
throw new Error("Enqueue operation failed");
|
|
9496
9501
|
}
|
|
@@ -9743,6 +9748,28 @@ var SimpleQueue = class {
|
|
|
9743
9748
|
return 1
|
|
9744
9749
|
`
|
|
9745
9750
|
});
|
|
9751
|
+
this.redis.defineCommand("enqueueItemWithCancellationKey", {
|
|
9752
|
+
numberOfKeys: 3,
|
|
9753
|
+
lua: `
|
|
9754
|
+
local queue = KEYS[1]
|
|
9755
|
+
local items = KEYS[2]
|
|
9756
|
+
local cancellationKey = KEYS[3]
|
|
9757
|
+
|
|
9758
|
+
local id = ARGV[1]
|
|
9759
|
+
local score = ARGV[2]
|
|
9760
|
+
local serializedItem = ARGV[3]
|
|
9761
|
+
|
|
9762
|
+
-- if the cancellation key exists, return 1
|
|
9763
|
+
if redis.call('EXISTS', cancellationKey) == 1 then
|
|
9764
|
+
return 1
|
|
9765
|
+
end
|
|
9766
|
+
|
|
9767
|
+
redis.call('ZADD', queue, score, id)
|
|
9768
|
+
redis.call('HSET', items, id, serializedItem)
|
|
9769
|
+
|
|
9770
|
+
return 1
|
|
9771
|
+
`
|
|
9772
|
+
});
|
|
9746
9773
|
this.redis.defineCommand("dequeueItems", {
|
|
9747
9774
|
numberOfKeys: 2,
|
|
9748
9775
|
lua: `
|
|
@@ -11195,7 +11222,8 @@ var Worker = class _Worker {
|
|
|
11195
11222
|
job,
|
|
11196
11223
|
payload,
|
|
11197
11224
|
visibilityTimeoutMs,
|
|
11198
|
-
availableAt
|
|
11225
|
+
availableAt,
|
|
11226
|
+
cancellationKey
|
|
11199
11227
|
}) {
|
|
11200
11228
|
return startSpan(
|
|
11201
11229
|
this.tracer,
|
|
@@ -11213,7 +11241,8 @@ var Worker = class _Worker {
|
|
|
11213
11241
|
job,
|
|
11214
11242
|
item: payload,
|
|
11215
11243
|
visibilityTimeoutMs: timeout,
|
|
11216
|
-
availableAt
|
|
11244
|
+
availableAt,
|
|
11245
|
+
cancellationKey
|
|
11217
11246
|
}),
|
|
11218
11247
|
{
|
|
11219
11248
|
job_type: String(job),
|
|
@@ -11302,6 +11331,16 @@ var Worker = class _Worker {
|
|
|
11302
11331
|
}
|
|
11303
11332
|
);
|
|
11304
11333
|
}
|
|
11334
|
+
/**
|
|
11335
|
+
* Cancels a job before it's enqueued.
|
|
11336
|
+
* @param cancellationKey - The cancellation key to cancel.
|
|
11337
|
+
* @returns A promise that resolves when the job is cancelled.
|
|
11338
|
+
*
|
|
11339
|
+
* Any jobs enqueued with the same cancellation key will be not be enqueued.
|
|
11340
|
+
*/
|
|
11341
|
+
cancel(cancellationKey) {
|
|
11342
|
+
return startSpan(this.tracer, "cancel", () => this.queue.cancel(cancellationKey));
|
|
11343
|
+
}
|
|
11305
11344
|
ack(id) {
|
|
11306
11345
|
return startSpan(
|
|
11307
11346
|
this.tracer,
|