@trigger.dev/redis-worker 4.0.0-v4-beta.24 → 4.0.0-v4-beta.26
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.cjs
CHANGED
|
@@ -9472,13 +9472,17 @@ var SimpleQueue = class {
|
|
|
9472
9472
|
this.#registerCommands();
|
|
9473
9473
|
this.schema = schema;
|
|
9474
9474
|
}
|
|
9475
|
+
async cancel(cancellationKey) {
|
|
9476
|
+
await this.redis.set(`cancellationKey:${cancellationKey}`, "1", "EX", 60 * 60 * 24);
|
|
9477
|
+
}
|
|
9475
9478
|
async enqueue({
|
|
9476
9479
|
id,
|
|
9477
9480
|
job,
|
|
9478
9481
|
item,
|
|
9479
9482
|
attempt,
|
|
9480
9483
|
availableAt,
|
|
9481
|
-
visibilityTimeoutMs
|
|
9484
|
+
visibilityTimeoutMs,
|
|
9485
|
+
cancellationKey
|
|
9482
9486
|
}) {
|
|
9483
9487
|
try {
|
|
9484
9488
|
const score = availableAt ? availableAt.getTime() : Date.now();
|
|
@@ -9490,13 +9494,14 @@ var SimpleQueue = class {
|
|
|
9490
9494
|
attempt,
|
|
9491
9495
|
deduplicationKey
|
|
9492
9496
|
});
|
|
9493
|
-
const result = await this.redis.
|
|
9497
|
+
const result = cancellationKey ? await this.redis.enqueueItemWithCancellationKey(
|
|
9494
9498
|
`queue`,
|
|
9495
9499
|
`items`,
|
|
9500
|
+
`cancellationKey:${cancellationKey}`,
|
|
9496
9501
|
id ?? nanoid(),
|
|
9497
9502
|
score,
|
|
9498
9503
|
serializedItem
|
|
9499
|
-
);
|
|
9504
|
+
) : await this.redis.enqueueItem(`queue`, `items`, id ?? nanoid(), score, serializedItem);
|
|
9500
9505
|
if (result !== 1) {
|
|
9501
9506
|
throw new Error("Enqueue operation failed");
|
|
9502
9507
|
}
|
|
@@ -9749,6 +9754,28 @@ var SimpleQueue = class {
|
|
|
9749
9754
|
return 1
|
|
9750
9755
|
`
|
|
9751
9756
|
});
|
|
9757
|
+
this.redis.defineCommand("enqueueItemWithCancellationKey", {
|
|
9758
|
+
numberOfKeys: 3,
|
|
9759
|
+
lua: `
|
|
9760
|
+
local queue = KEYS[1]
|
|
9761
|
+
local items = KEYS[2]
|
|
9762
|
+
local cancellationKey = KEYS[3]
|
|
9763
|
+
|
|
9764
|
+
local id = ARGV[1]
|
|
9765
|
+
local score = ARGV[2]
|
|
9766
|
+
local serializedItem = ARGV[3]
|
|
9767
|
+
|
|
9768
|
+
-- if the cancellation key exists, return 1
|
|
9769
|
+
if redis.call('EXISTS', cancellationKey) == 1 then
|
|
9770
|
+
return 1
|
|
9771
|
+
end
|
|
9772
|
+
|
|
9773
|
+
redis.call('ZADD', queue, score, id)
|
|
9774
|
+
redis.call('HSET', items, id, serializedItem)
|
|
9775
|
+
|
|
9776
|
+
return 1
|
|
9777
|
+
`
|
|
9778
|
+
});
|
|
9752
9779
|
this.redis.defineCommand("dequeueItems", {
|
|
9753
9780
|
numberOfKeys: 2,
|
|
9754
9781
|
lua: `
|
|
@@ -11201,7 +11228,8 @@ var Worker = class _Worker {
|
|
|
11201
11228
|
job,
|
|
11202
11229
|
payload,
|
|
11203
11230
|
visibilityTimeoutMs,
|
|
11204
|
-
availableAt
|
|
11231
|
+
availableAt,
|
|
11232
|
+
cancellationKey
|
|
11205
11233
|
}) {
|
|
11206
11234
|
return startSpan(
|
|
11207
11235
|
this.tracer,
|
|
@@ -11219,7 +11247,8 @@ var Worker = class _Worker {
|
|
|
11219
11247
|
job,
|
|
11220
11248
|
item: payload,
|
|
11221
11249
|
visibilityTimeoutMs: timeout,
|
|
11222
|
-
availableAt
|
|
11250
|
+
availableAt,
|
|
11251
|
+
cancellationKey
|
|
11223
11252
|
}),
|
|
11224
11253
|
{
|
|
11225
11254
|
job_type: String(job),
|
|
@@ -11308,6 +11337,16 @@ var Worker = class _Worker {
|
|
|
11308
11337
|
}
|
|
11309
11338
|
);
|
|
11310
11339
|
}
|
|
11340
|
+
/**
|
|
11341
|
+
* Cancels a job before it's enqueued.
|
|
11342
|
+
* @param cancellationKey - The cancellation key to cancel.
|
|
11343
|
+
* @returns A promise that resolves when the job is cancelled.
|
|
11344
|
+
*
|
|
11345
|
+
* Any jobs enqueued with the same cancellation key will be not be enqueued.
|
|
11346
|
+
*/
|
|
11347
|
+
cancel(cancellationKey) {
|
|
11348
|
+
return startSpan(this.tracer, "cancel", () => this.queue.cancel(cancellationKey));
|
|
11349
|
+
}
|
|
11311
11350
|
ack(id) {
|
|
11312
11351
|
return startSpan(
|
|
11313
11352
|
this.tracer,
|