@trigger.dev/redis-worker 4.5.0 → 4.5.2

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