@trigger.dev/redis-worker 0.0.0-prerelease-20251211173228 → 0.0.0-prerelease-20251218163312
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 +43 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +43 -7
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -12510,8 +12510,12 @@ var VisibilityManager = class {
|
|
|
12510
12510
|
const inflightKey = this.keys.inflightKey(shardId);
|
|
12511
12511
|
const member = this.#makeMember(messageId, queueId);
|
|
12512
12512
|
const newDeadline = Date.now() + extendMs;
|
|
12513
|
-
const result = await this.redis.
|
|
12514
|
-
|
|
12513
|
+
const result = await this.redis.heartbeatMessage(
|
|
12514
|
+
inflightKey,
|
|
12515
|
+
member,
|
|
12516
|
+
newDeadline.toString()
|
|
12517
|
+
);
|
|
12518
|
+
const success = result === 1;
|
|
12515
12519
|
if (success) {
|
|
12516
12520
|
this.logger.debug("Heartbeat successful", {
|
|
12517
12521
|
messageId,
|
|
@@ -12768,6 +12772,24 @@ redis.call('HDEL', inflightDataKey, messageId)
|
|
|
12768
12772
|
redis.call('ZADD', queueKey, score, messageId)
|
|
12769
12773
|
redis.call('HSET', queueItemsKey, messageId, payload)
|
|
12770
12774
|
|
|
12775
|
+
return 1
|
|
12776
|
+
`
|
|
12777
|
+
});
|
|
12778
|
+
this.redis.defineCommand("heartbeatMessage", {
|
|
12779
|
+
numberOfKeys: 1,
|
|
12780
|
+
lua: `
|
|
12781
|
+
local inflightKey = KEYS[1]
|
|
12782
|
+
local member = ARGV[1]
|
|
12783
|
+
local newDeadline = tonumber(ARGV[2])
|
|
12784
|
+
|
|
12785
|
+
-- Check if member exists in the in-flight set
|
|
12786
|
+
local score = redis.call('ZSCORE', inflightKey, member)
|
|
12787
|
+
if not score then
|
|
12788
|
+
return 0
|
|
12789
|
+
end
|
|
12790
|
+
|
|
12791
|
+
-- Update the deadline
|
|
12792
|
+
redis.call('ZADD', inflightKey, 'XX', newDeadline, member)
|
|
12771
12793
|
return 1
|
|
12772
12794
|
`
|
|
12773
12795
|
});
|
|
@@ -13533,7 +13555,10 @@ var WeightedScheduler = class extends BaseScheduler {
|
|
|
13533
13555
|
return { tenantId, avgAge };
|
|
13534
13556
|
});
|
|
13535
13557
|
const maxAge = Math.max(...tenantAges.map((t) => t.avgAge));
|
|
13536
|
-
const weightedTenants = tenantAges.map((t) => ({
|
|
13558
|
+
const weightedTenants = maxAge === 0 ? tenantAges.map((t) => ({
|
|
13559
|
+
tenantId: t.tenantId,
|
|
13560
|
+
weight: 1 / tenantAges.length
|
|
13561
|
+
})) : tenantAges.map((t) => ({
|
|
13537
13562
|
tenantId: t.tenantId,
|
|
13538
13563
|
weight: t.avgAge / maxAge
|
|
13539
13564
|
}));
|
|
@@ -13576,11 +13601,11 @@ var WeightedScheduler = class extends BaseScheduler {
|
|
|
13576
13601
|
const tenant = snapshot.tenants.get(tenantId);
|
|
13577
13602
|
let weight = 1;
|
|
13578
13603
|
if (concurrencyLimitBias > 0) {
|
|
13579
|
-
const normalizedLimit = tenant.concurrency.limit / maxLimit;
|
|
13604
|
+
const normalizedLimit = maxLimit > 0 ? tenant.concurrency.limit / maxLimit : 0;
|
|
13580
13605
|
weight *= 1 + Math.pow(normalizedLimit * concurrencyLimitBias, 2);
|
|
13581
13606
|
}
|
|
13582
13607
|
if (availableCapacityBias > 0) {
|
|
13583
|
-
const usedPercentage = tenant.concurrency.current / tenant.concurrency.limit;
|
|
13608
|
+
const usedPercentage = tenant.concurrency.limit > 0 ? tenant.concurrency.current / tenant.concurrency.limit : 1;
|
|
13584
13609
|
const availableBonus = 1 - usedPercentage;
|
|
13585
13610
|
weight *= 1 + Math.pow(availableBonus * availableCapacityBias, 2);
|
|
13586
13611
|
}
|
|
@@ -13599,9 +13624,10 @@ var WeightedScheduler = class extends BaseScheduler {
|
|
|
13599
13624
|
return queues.sort((a, b) => b.age - a.age).map((q) => q.queueId);
|
|
13600
13625
|
}
|
|
13601
13626
|
const maxAge = Math.max(...queues.map((q) => q.age));
|
|
13627
|
+
const ageDenom = maxAge === 0 ? 1 : maxAge;
|
|
13602
13628
|
const weightedQueues = queues.map((q) => ({
|
|
13603
13629
|
queue: q,
|
|
13604
|
-
weight: 1 + q.age /
|
|
13630
|
+
weight: 1 + q.age / ageDenom * queueAgeRandomization
|
|
13605
13631
|
}));
|
|
13606
13632
|
const result = [];
|
|
13607
13633
|
let remaining = [...weightedQueues];
|
|
@@ -14678,6 +14704,17 @@ var FairQueue = class {
|
|
|
14678
14704
|
error: result.error.message
|
|
14679
14705
|
});
|
|
14680
14706
|
await this.#moveToDeadLetterQueue(storedMessage, "Payload validation failed");
|
|
14707
|
+
if (this.concurrencyManager) {
|
|
14708
|
+
try {
|
|
14709
|
+
await this.concurrencyManager.release(descriptor, storedMessage.id);
|
|
14710
|
+
} catch (releaseError) {
|
|
14711
|
+
this.logger.error("Failed to release concurrency slot after payload validation failure", {
|
|
14712
|
+
messageId: storedMessage.id,
|
|
14713
|
+
queueId,
|
|
14714
|
+
error: releaseError instanceof Error ? releaseError.message : String(releaseError)
|
|
14715
|
+
});
|
|
14716
|
+
}
|
|
14717
|
+
}
|
|
14681
14718
|
return;
|
|
14682
14719
|
}
|
|
14683
14720
|
payload = result.data;
|
|
@@ -14854,7 +14891,6 @@ var FairQueue = class {
|
|
|
14854
14891
|
}
|
|
14855
14892
|
async #moveToDeadLetterQueue(storedMessage, errorMessage) {
|
|
14856
14893
|
if (!this.deadLetterQueueEnabled) {
|
|
14857
|
-
this.masterQueue.getShardForQueue(storedMessage.queueId);
|
|
14858
14894
|
await this.visibilityManager.complete(storedMessage.id, storedMessage.queueId);
|
|
14859
14895
|
return;
|
|
14860
14896
|
}
|