@trigger.dev/redis-worker 4.5.0 → 4.5.1

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 CHANGED
@@ -9060,7 +9060,7 @@ var require_Redis = __commonJS({
9060
9060
  var lodash_1 = require_lodash3();
9061
9061
  var Deque = require_denque();
9062
9062
  var debug = (0, utils_1.Debug)("redis");
9063
- var Redis4 = class _Redis extends Commander_1.default {
9063
+ var Redis3 = class _Redis extends Commander_1.default {
9064
9064
  constructor(arg1, arg2, arg3) {
9065
9065
  super();
9066
9066
  this.status = "wait";
@@ -9639,12 +9639,12 @@ var require_Redis = __commonJS({
9639
9639
  }).catch(lodash_1.noop);
9640
9640
  }
9641
9641
  };
9642
- Redis4.Cluster = cluster_1.default;
9643
- Redis4.Command = Command_1.default;
9644
- Redis4.defaultOptions = RedisOptions_1.DEFAULT_REDIS_OPTIONS;
9645
- (0, applyMixin_1.default)(Redis4, events_1.EventEmitter);
9646
- (0, transaction_1.addTransactionSupport)(Redis4.prototype);
9647
- exports$1.default = Redis4;
9642
+ Redis3.Cluster = cluster_1.default;
9643
+ Redis3.Command = Command_1.default;
9644
+ Redis3.defaultOptions = RedisOptions_1.DEFAULT_REDIS_OPTIONS;
9645
+ (0, applyMixin_1.default)(Redis3, events_1.EventEmitter);
9646
+ (0, transaction_1.addTransactionSupport)(Redis3.prototype);
9647
+ exports$1.default = Redis3;
9648
9648
  }
9649
9649
  });
9650
9650
 
@@ -12725,135 +12725,6 @@ return 1
12725
12725
  });
12726
12726
  }
12727
12727
  };
12728
- var TenantDispatch = class {
12729
- constructor(options) {
12730
- this.options = options;
12731
- this.redis = createRedisClient(options.redis);
12732
- this.keys = options.keys;
12733
- this.shardCount = Math.max(1, options.shardCount);
12734
- }
12735
- redis;
12736
- keys;
12737
- shardCount;
12738
- /**
12739
- * Get the dispatch shard ID for a tenant.
12740
- * Uses jump consistent hash on the tenant ID so each tenant
12741
- * always maps to exactly one dispatch shard.
12742
- */
12743
- getShardForTenant(tenantId) {
12744
- return serverOnly.jumpHash(tenantId, this.shardCount);
12745
- }
12746
- /**
12747
- * Get eligible tenants from a dispatch shard (Level 1).
12748
- * Returns tenants ordered by oldest message (lowest score first).
12749
- */
12750
- async getTenantsFromShard(shardId, limit = 1e3, maxScore) {
12751
- const dispatchKey = this.keys.dispatchKey(shardId);
12752
- const score = maxScore ?? Date.now();
12753
- const results = await this.redis.zrangebyscore(
12754
- dispatchKey,
12755
- "-inf",
12756
- score,
12757
- "WITHSCORES",
12758
- "LIMIT",
12759
- 0,
12760
- limit
12761
- );
12762
- const tenants = [];
12763
- for (let i = 0; i < results.length; i += 2) {
12764
- const tenantId = results[i];
12765
- const scoreStr = results[i + 1];
12766
- if (tenantId && scoreStr) {
12767
- tenants.push({
12768
- tenantId,
12769
- score: parseFloat(scoreStr)
12770
- });
12771
- }
12772
- }
12773
- return tenants;
12774
- }
12775
- /**
12776
- * Get queues for a specific tenant (Level 2).
12777
- * Returns queues ordered by oldest message (lowest score first).
12778
- */
12779
- async getQueuesForTenant(tenantId, limit = 1e3, maxScore) {
12780
- const tenantQueueKey = this.keys.tenantQueueIndexKey(tenantId);
12781
- const score = maxScore ?? Date.now();
12782
- const results = await this.redis.zrangebyscore(
12783
- tenantQueueKey,
12784
- "-inf",
12785
- score,
12786
- "WITHSCORES",
12787
- "LIMIT",
12788
- 0,
12789
- limit
12790
- );
12791
- const queues = [];
12792
- for (let i = 0; i < results.length; i += 2) {
12793
- const queueId = results[i];
12794
- const scoreStr = results[i + 1];
12795
- if (queueId && scoreStr) {
12796
- queues.push({
12797
- queueId,
12798
- score: parseFloat(scoreStr),
12799
- tenantId
12800
- });
12801
- }
12802
- }
12803
- return queues;
12804
- }
12805
- /**
12806
- * Get the number of tenants in a dispatch shard.
12807
- */
12808
- async getShardTenantCount(shardId) {
12809
- const dispatchKey = this.keys.dispatchKey(shardId);
12810
- return await this.redis.zcard(dispatchKey);
12811
- }
12812
- /**
12813
- * Get total tenant count across all dispatch shards.
12814
- * Note: tenants may appear in multiple shards, so this may overcount.
12815
- */
12816
- async getTotalTenantCount() {
12817
- const counts = await Promise.all(
12818
- Array.from({ length: this.shardCount }, (_, i) => this.getShardTenantCount(i))
12819
- );
12820
- return counts.reduce((sum, count) => sum + count, 0);
12821
- }
12822
- /**
12823
- * Get the number of queues for a tenant.
12824
- */
12825
- async getTenantQueueCount(tenantId) {
12826
- const tenantQueueKey = this.keys.tenantQueueIndexKey(tenantId);
12827
- return await this.redis.zcard(tenantQueueKey);
12828
- }
12829
- /**
12830
- * Remove a tenant from a specific dispatch shard.
12831
- */
12832
- async removeTenantFromShard(shardId, tenantId) {
12833
- const dispatchKey = this.keys.dispatchKey(shardId);
12834
- await this.redis.zrem(dispatchKey, tenantId);
12835
- }
12836
- /**
12837
- * Add a tenant to a dispatch shard with the given score.
12838
- */
12839
- async addTenantToShard(shardId, tenantId, score) {
12840
- const dispatchKey = this.keys.dispatchKey(shardId);
12841
- await this.redis.zadd(dispatchKey, score, tenantId);
12842
- }
12843
- /**
12844
- * Remove a queue from a tenant's queue index.
12845
- */
12846
- async removeQueueFromTenant(tenantId, queueId) {
12847
- const tenantQueueKey = this.keys.tenantQueueIndexKey(tenantId);
12848
- await this.redis.zrem(tenantQueueKey, queueId);
12849
- }
12850
- /**
12851
- * Close the Redis connection.
12852
- */
12853
- async close() {
12854
- await this.redis.quit();
12855
- }
12856
- };
12857
12728
 
12858
12729
  // src/fair-queue/telemetry.ts
12859
12730
  var FairQueueAttributes = {
@@ -13368,6 +13239,135 @@ var noopSpan = {
13368
13239
  }
13369
13240
  };
13370
13241
  var noopTelemetry = new FairQueueTelemetry({});
13242
+ var TenantDispatch = class {
13243
+ constructor(options) {
13244
+ this.options = options;
13245
+ this.redis = createRedisClient(options.redis);
13246
+ this.keys = options.keys;
13247
+ this.shardCount = Math.max(1, options.shardCount);
13248
+ }
13249
+ redis;
13250
+ keys;
13251
+ shardCount;
13252
+ /**
13253
+ * Get the dispatch shard ID for a tenant.
13254
+ * Uses jump consistent hash on the tenant ID so each tenant
13255
+ * always maps to exactly one dispatch shard.
13256
+ */
13257
+ getShardForTenant(tenantId) {
13258
+ return serverOnly.jumpHash(tenantId, this.shardCount);
13259
+ }
13260
+ /**
13261
+ * Get eligible tenants from a dispatch shard (Level 1).
13262
+ * Returns tenants ordered by oldest message (lowest score first).
13263
+ */
13264
+ async getTenantsFromShard(shardId, limit = 1e3, maxScore) {
13265
+ const dispatchKey = this.keys.dispatchKey(shardId);
13266
+ const score = maxScore ?? Date.now();
13267
+ const results = await this.redis.zrangebyscore(
13268
+ dispatchKey,
13269
+ "-inf",
13270
+ score,
13271
+ "WITHSCORES",
13272
+ "LIMIT",
13273
+ 0,
13274
+ limit
13275
+ );
13276
+ const tenants = [];
13277
+ for (let i = 0; i < results.length; i += 2) {
13278
+ const tenantId = results[i];
13279
+ const scoreStr = results[i + 1];
13280
+ if (tenantId && scoreStr) {
13281
+ tenants.push({
13282
+ tenantId,
13283
+ score: parseFloat(scoreStr)
13284
+ });
13285
+ }
13286
+ }
13287
+ return tenants;
13288
+ }
13289
+ /**
13290
+ * Get queues for a specific tenant (Level 2).
13291
+ * Returns queues ordered by oldest message (lowest score first).
13292
+ */
13293
+ async getQueuesForTenant(tenantId, limit = 1e3, maxScore) {
13294
+ const tenantQueueKey = this.keys.tenantQueueIndexKey(tenantId);
13295
+ const score = maxScore ?? Date.now();
13296
+ const results = await this.redis.zrangebyscore(
13297
+ tenantQueueKey,
13298
+ "-inf",
13299
+ score,
13300
+ "WITHSCORES",
13301
+ "LIMIT",
13302
+ 0,
13303
+ limit
13304
+ );
13305
+ const queues = [];
13306
+ for (let i = 0; i < results.length; i += 2) {
13307
+ const queueId = results[i];
13308
+ const scoreStr = results[i + 1];
13309
+ if (queueId && scoreStr) {
13310
+ queues.push({
13311
+ queueId,
13312
+ score: parseFloat(scoreStr),
13313
+ tenantId
13314
+ });
13315
+ }
13316
+ }
13317
+ return queues;
13318
+ }
13319
+ /**
13320
+ * Get the number of tenants in a dispatch shard.
13321
+ */
13322
+ async getShardTenantCount(shardId) {
13323
+ const dispatchKey = this.keys.dispatchKey(shardId);
13324
+ return await this.redis.zcard(dispatchKey);
13325
+ }
13326
+ /**
13327
+ * Get total tenant count across all dispatch shards.
13328
+ * Note: tenants may appear in multiple shards, so this may overcount.
13329
+ */
13330
+ async getTotalTenantCount() {
13331
+ const counts = await Promise.all(
13332
+ Array.from({ length: this.shardCount }, (_, i) => this.getShardTenantCount(i))
13333
+ );
13334
+ return counts.reduce((sum, count) => sum + count, 0);
13335
+ }
13336
+ /**
13337
+ * Get the number of queues for a tenant.
13338
+ */
13339
+ async getTenantQueueCount(tenantId) {
13340
+ const tenantQueueKey = this.keys.tenantQueueIndexKey(tenantId);
13341
+ return await this.redis.zcard(tenantQueueKey);
13342
+ }
13343
+ /**
13344
+ * Remove a tenant from a specific dispatch shard.
13345
+ */
13346
+ async removeTenantFromShard(shardId, tenantId) {
13347
+ const dispatchKey = this.keys.dispatchKey(shardId);
13348
+ await this.redis.zrem(dispatchKey, tenantId);
13349
+ }
13350
+ /**
13351
+ * Add a tenant to a dispatch shard with the given score.
13352
+ */
13353
+ async addTenantToShard(shardId, tenantId, score) {
13354
+ const dispatchKey = this.keys.dispatchKey(shardId);
13355
+ await this.redis.zadd(dispatchKey, score, tenantId);
13356
+ }
13357
+ /**
13358
+ * Remove a queue from a tenant's queue index.
13359
+ */
13360
+ async removeQueueFromTenant(tenantId, queueId) {
13361
+ const tenantQueueKey = this.keys.tenantQueueIndexKey(tenantId);
13362
+ await this.redis.zrem(tenantQueueKey, queueId);
13363
+ }
13364
+ /**
13365
+ * Close the Redis connection.
13366
+ */
13367
+ async close() {
13368
+ await this.redis.quit();
13369
+ }
13370
+ };
13371
13371
  var VisibilityManager = class {
13372
13372
  constructor(options) {
13373
13373
  this.options = options;
@@ -14349,6 +14349,101 @@ var CallbackFairQueueKeyProducer = class extends DefaultFairQueueKeyProducer {
14349
14349
  return this.groupExtractor(groupName, queueId);
14350
14350
  }
14351
14351
  };
14352
+ var ExponentialBackoffRetry = class {
14353
+ maxAttempts;
14354
+ options;
14355
+ constructor(options) {
14356
+ this.options = {
14357
+ maxAttempts: options?.maxAttempts ?? 12,
14358
+ factor: options?.factor ?? 2,
14359
+ minTimeoutInMs: options?.minTimeoutInMs ?? 1e3,
14360
+ maxTimeoutInMs: options?.maxTimeoutInMs ?? 36e5,
14361
+ // 1 hour
14362
+ randomize: options?.randomize ?? true
14363
+ };
14364
+ this.maxAttempts = this.options.maxAttempts ?? 12;
14365
+ }
14366
+ getNextDelay(attempt, _error) {
14367
+ if (attempt >= this.maxAttempts) {
14368
+ return null;
14369
+ }
14370
+ const delay = v3.calculateNextRetryDelay(this.options, attempt);
14371
+ return delay ?? null;
14372
+ }
14373
+ };
14374
+ var FixedDelayRetry = class {
14375
+ maxAttempts;
14376
+ delayMs;
14377
+ constructor(options) {
14378
+ this.maxAttempts = options.maxAttempts;
14379
+ this.delayMs = options.delayMs;
14380
+ }
14381
+ getNextDelay(attempt, _error) {
14382
+ if (attempt >= this.maxAttempts) {
14383
+ return null;
14384
+ }
14385
+ return this.delayMs;
14386
+ }
14387
+ };
14388
+ var LinearBackoffRetry = class {
14389
+ maxAttempts;
14390
+ baseDelayMs;
14391
+ maxDelayMs;
14392
+ constructor(options) {
14393
+ this.maxAttempts = options.maxAttempts;
14394
+ this.baseDelayMs = options.baseDelayMs;
14395
+ this.maxDelayMs = options.maxDelayMs ?? options.baseDelayMs * options.maxAttempts;
14396
+ }
14397
+ getNextDelay(attempt, _error) {
14398
+ if (attempt >= this.maxAttempts) {
14399
+ return null;
14400
+ }
14401
+ const delay = this.baseDelayMs * attempt;
14402
+ return Math.min(delay, this.maxDelayMs);
14403
+ }
14404
+ };
14405
+ var NoRetry = class {
14406
+ maxAttempts = 1;
14407
+ getNextDelay(_attempt, _error) {
14408
+ return null;
14409
+ }
14410
+ };
14411
+ var ImmediateRetry = class {
14412
+ maxAttempts;
14413
+ constructor(maxAttempts) {
14414
+ this.maxAttempts = maxAttempts;
14415
+ }
14416
+ getNextDelay(attempt, _error) {
14417
+ if (attempt >= this.maxAttempts) {
14418
+ return null;
14419
+ }
14420
+ return 0;
14421
+ }
14422
+ };
14423
+ var CustomRetry = class {
14424
+ maxAttempts;
14425
+ calculateDelay;
14426
+ constructor(options) {
14427
+ this.maxAttempts = options.maxAttempts;
14428
+ this.calculateDelay = options.calculateDelay;
14429
+ }
14430
+ getNextDelay(attempt, error) {
14431
+ if (attempt >= this.maxAttempts) {
14432
+ return null;
14433
+ }
14434
+ return this.calculateDelay(attempt, error);
14435
+ }
14436
+ };
14437
+ var defaultRetryOptions = {
14438
+ maxAttempts: 12,
14439
+ factor: 2,
14440
+ minTimeoutInMs: 1e3,
14441
+ maxTimeoutInMs: 36e5,
14442
+ randomize: true
14443
+ };
14444
+ function createDefaultRetryStrategy() {
14445
+ return new ExponentialBackoffRetry(defaultRetryOptions);
14446
+ }
14352
14447
 
14353
14448
  // src/fair-queue/scheduler.ts
14354
14449
  var BaseScheduler = class {
@@ -15121,101 +15216,6 @@ var RoundRobinScheduler = class extends BaseScheduler {
15121
15216
  return [...array.slice(normalizedIndex), ...array.slice(0, normalizedIndex)];
15122
15217
  }
15123
15218
  };
15124
- var ExponentialBackoffRetry = class {
15125
- maxAttempts;
15126
- options;
15127
- constructor(options) {
15128
- this.options = {
15129
- maxAttempts: options?.maxAttempts ?? 12,
15130
- factor: options?.factor ?? 2,
15131
- minTimeoutInMs: options?.minTimeoutInMs ?? 1e3,
15132
- maxTimeoutInMs: options?.maxTimeoutInMs ?? 36e5,
15133
- // 1 hour
15134
- randomize: options?.randomize ?? true
15135
- };
15136
- this.maxAttempts = this.options.maxAttempts ?? 12;
15137
- }
15138
- getNextDelay(attempt, _error) {
15139
- if (attempt >= this.maxAttempts) {
15140
- return null;
15141
- }
15142
- const delay = v3.calculateNextRetryDelay(this.options, attempt);
15143
- return delay ?? null;
15144
- }
15145
- };
15146
- var FixedDelayRetry = class {
15147
- maxAttempts;
15148
- delayMs;
15149
- constructor(options) {
15150
- this.maxAttempts = options.maxAttempts;
15151
- this.delayMs = options.delayMs;
15152
- }
15153
- getNextDelay(attempt, _error) {
15154
- if (attempt >= this.maxAttempts) {
15155
- return null;
15156
- }
15157
- return this.delayMs;
15158
- }
15159
- };
15160
- var LinearBackoffRetry = class {
15161
- maxAttempts;
15162
- baseDelayMs;
15163
- maxDelayMs;
15164
- constructor(options) {
15165
- this.maxAttempts = options.maxAttempts;
15166
- this.baseDelayMs = options.baseDelayMs;
15167
- this.maxDelayMs = options.maxDelayMs ?? options.baseDelayMs * options.maxAttempts;
15168
- }
15169
- getNextDelay(attempt, _error) {
15170
- if (attempt >= this.maxAttempts) {
15171
- return null;
15172
- }
15173
- const delay = this.baseDelayMs * attempt;
15174
- return Math.min(delay, this.maxDelayMs);
15175
- }
15176
- };
15177
- var NoRetry = class {
15178
- maxAttempts = 1;
15179
- getNextDelay(_attempt, _error) {
15180
- return null;
15181
- }
15182
- };
15183
- var ImmediateRetry = class {
15184
- maxAttempts;
15185
- constructor(maxAttempts) {
15186
- this.maxAttempts = maxAttempts;
15187
- }
15188
- getNextDelay(attempt, _error) {
15189
- if (attempt >= this.maxAttempts) {
15190
- return null;
15191
- }
15192
- return 0;
15193
- }
15194
- };
15195
- var CustomRetry = class {
15196
- maxAttempts;
15197
- calculateDelay;
15198
- constructor(options) {
15199
- this.maxAttempts = options.maxAttempts;
15200
- this.calculateDelay = options.calculateDelay;
15201
- }
15202
- getNextDelay(attempt, error) {
15203
- if (attempt >= this.maxAttempts) {
15204
- return null;
15205
- }
15206
- return this.calculateDelay(attempt, error);
15207
- }
15208
- };
15209
- var defaultRetryOptions = {
15210
- maxAttempts: 12,
15211
- factor: 2,
15212
- minTimeoutInMs: 1e3,
15213
- maxTimeoutInMs: 36e5,
15214
- randomize: true
15215
- };
15216
- function createDefaultRetryStrategy() {
15217
- return new ExponentialBackoffRetry(defaultRetryOptions);
15218
- }
15219
15219
 
15220
15220
  // src/fair-queue/index.ts
15221
15221
  var FairQueue = class {