@trigger.dev/redis-worker 0.0.0-prerelease-20260302145933 → 0.0.0-prerelease-20260305142821

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.d.cts CHANGED
@@ -722,8 +722,22 @@ interface FairQueueOptions<TPayloadSchema extends z.ZodTypeAny = z.ZodUnknown> {
722
722
  meter?: Meter;
723
723
  /** Name for metrics/tracing (default: "fairqueue") */
724
724
  name?: string;
725
- /** Optional global rate limiter to limit processing across all consumers */
726
- globalRateLimiter?: GlobalRateLimiter;
725
+ /**
726
+ * Maximum number of items allowed in a worker queue before claiming pauses.
727
+ * When set, the claim phase checks worker queue depth and skips claiming if
728
+ * the queue is at or above this limit. This prevents unbounded worker queue
729
+ * growth which could cause visibility timeouts (claimed messages have a
730
+ * visibility timeout that ticks while they sit in the worker queue).
731
+ * Requires `workerQueueDepthCheckId` to know which queue to check.
732
+ * Disabled by default (0 = no limit).
733
+ */
734
+ workerQueueMaxDepth?: number;
735
+ /**
736
+ * The worker queue ID to check depth against when workerQueueMaxDepth is set.
737
+ * Required when workerQueueMaxDepth > 0 and the system uses a single shared worker queue.
738
+ * If not set, depth checking is disabled even if workerQueueMaxDepth is set.
739
+ */
740
+ workerQueueDepthCheckId?: string;
727
741
  }
728
742
  /**
729
743
  * Context passed to the message handler.
@@ -1958,7 +1972,8 @@ declare class FairQueue<TPayloadSchema extends z.ZodTypeAny = z.ZodUnknown> {
1958
1972
  private cooloffPeriodMs;
1959
1973
  private maxCooloffStatesSize;
1960
1974
  private queueCooloffStates;
1961
- private globalRateLimiter?;
1975
+ private workerQueueMaxDepth;
1976
+ private workerQueueDepthCheckId?;
1962
1977
  private consumerTraceMaxIterations;
1963
1978
  private consumerTraceTimeoutSeconds;
1964
1979
  private batchedSpanManager;
package/dist/index.d.ts CHANGED
@@ -722,8 +722,22 @@ interface FairQueueOptions<TPayloadSchema extends z.ZodTypeAny = z.ZodUnknown> {
722
722
  meter?: Meter;
723
723
  /** Name for metrics/tracing (default: "fairqueue") */
724
724
  name?: string;
725
- /** Optional global rate limiter to limit processing across all consumers */
726
- globalRateLimiter?: GlobalRateLimiter;
725
+ /**
726
+ * Maximum number of items allowed in a worker queue before claiming pauses.
727
+ * When set, the claim phase checks worker queue depth and skips claiming if
728
+ * the queue is at or above this limit. This prevents unbounded worker queue
729
+ * growth which could cause visibility timeouts (claimed messages have a
730
+ * visibility timeout that ticks while they sit in the worker queue).
731
+ * Requires `workerQueueDepthCheckId` to know which queue to check.
732
+ * Disabled by default (0 = no limit).
733
+ */
734
+ workerQueueMaxDepth?: number;
735
+ /**
736
+ * The worker queue ID to check depth against when workerQueueMaxDepth is set.
737
+ * Required when workerQueueMaxDepth > 0 and the system uses a single shared worker queue.
738
+ * If not set, depth checking is disabled even if workerQueueMaxDepth is set.
739
+ */
740
+ workerQueueDepthCheckId?: string;
727
741
  }
728
742
  /**
729
743
  * Context passed to the message handler.
@@ -1958,7 +1972,8 @@ declare class FairQueue<TPayloadSchema extends z.ZodTypeAny = z.ZodUnknown> {
1958
1972
  private cooloffPeriodMs;
1959
1973
  private maxCooloffStatesSize;
1960
1974
  private queueCooloffStates;
1961
- private globalRateLimiter?;
1975
+ private workerQueueMaxDepth;
1976
+ private workerQueueDepthCheckId?;
1962
1977
  private consumerTraceMaxIterations;
1963
1978
  private consumerTraceTimeoutSeconds;
1964
1979
  private batchedSpanManager;
package/dist/index.js CHANGED
@@ -14902,7 +14902,8 @@ var FairQueue = class {
14902
14902
  this.cooloffThreshold = options.cooloff?.threshold ?? 10;
14903
14903
  this.cooloffPeriodMs = options.cooloff?.periodMs ?? 1e4;
14904
14904
  this.maxCooloffStatesSize = options.cooloff?.maxStatesSize ?? 1e3;
14905
- this.globalRateLimiter = options.globalRateLimiter;
14905
+ this.workerQueueMaxDepth = options.workerQueueMaxDepth ?? 0;
14906
+ this.workerQueueDepthCheckId = options.workerQueueDepthCheckId;
14906
14907
  this.consumerTraceMaxIterations = options.consumerTraceMaxIterations ?? 500;
14907
14908
  this.consumerTraceTimeoutSeconds = options.consumerTraceTimeoutSeconds ?? 60;
14908
14909
  this.telemetry = new FairQueueTelemetry({
@@ -14988,8 +14989,9 @@ var FairQueue = class {
14988
14989
  cooloffPeriodMs;
14989
14990
  maxCooloffStatesSize;
14990
14991
  queueCooloffStates = /* @__PURE__ */ new Map();
14991
- // Global rate limiter
14992
- globalRateLimiter;
14992
+ // Worker queue backpressure
14993
+ workerQueueMaxDepth;
14994
+ workerQueueDepthCheckId;
14993
14995
  // Consumer tracing
14994
14996
  consumerTraceMaxIterations;
14995
14997
  consumerTraceTimeoutSeconds;
@@ -15693,15 +15695,13 @@ var FairQueue = class {
15693
15695
  }
15694
15696
  maxClaimCount = Math.min(maxClaimCount, availableCapacity);
15695
15697
  }
15696
- if (this.globalRateLimiter) {
15697
- const result = await this.globalRateLimiter.limit();
15698
- if (!result.allowed && result.resetAt) {
15699
- const waitMs = Math.max(0, result.resetAt - Date.now());
15700
- if (waitMs > 0) {
15701
- this.logger.debug("Global rate limit reached, waiting", { waitMs, loopId });
15702
- await new Promise((resolve) => setTimeout(resolve, waitMs));
15703
- }
15698
+ if (this.workerQueueMaxDepth > 0 && this.workerQueueDepthCheckId) {
15699
+ const depth = await this.workerQueueManager.getLength(this.workerQueueDepthCheckId);
15700
+ if (depth >= this.workerQueueMaxDepth) {
15701
+ return 0;
15704
15702
  }
15703
+ const remainingCapacity = this.workerQueueMaxDepth - depth;
15704
+ maxClaimCount = Math.min(maxClaimCount, remainingCapacity);
15705
15705
  }
15706
15706
  const claimedMessages = await this.visibilityManager.claimBatch(queueId, queueKey, queueItemsKey, loopId, maxClaimCount, this.visibilityTimeoutMs);
15707
15707
  if (claimedMessages.length === 0) {