@trigger.dev/redis-worker 0.0.0-process-keep-alive-20250620100954 → 0.0.0-process-keep-alive-20250623153513

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
@@ -11151,7 +11151,7 @@ var Worker = class _Worker {
11151
11151
  start() {
11152
11152
  const { workers, tasksPerWorker } = this.concurrency;
11153
11153
  for (let i = 0; i < workers; i++) {
11154
- this.workerLoops.push(this.runWorkerLoop(`worker-${nanoid(12)}`, tasksPerWorker));
11154
+ this.workerLoops.push(this.runWorkerLoop(`worker-${nanoid(12)}`, tasksPerWorker, i, workers));
11155
11155
  }
11156
11156
  this.setupShutdownHandlers();
11157
11157
  this.subscriber = createRedisClient(this.options.redisOptions, {
@@ -11308,11 +11308,30 @@ var Worker = class _Worker {
11308
11308
  * The main loop that each worker runs. It repeatedly polls for items,
11309
11309
  * processes them, and then waits before the next iteration.
11310
11310
  */
11311
- async runWorkerLoop(workerId, taskCount) {
11311
+ async runWorkerLoop(workerId, taskCount, workerIndex, totalWorkers) {
11312
11312
  const pollIntervalMs = this.options.pollIntervalMs ?? 1e3;
11313
11313
  const immediatePollIntervalMs = this.options.immediatePollIntervalMs ?? 100;
11314
+ const delayBetweenWorkers = this.options.pollIntervalMs ?? 1e3;
11315
+ const delay = delayBetweenWorkers * (totalWorkers - workerIndex);
11316
+ await _Worker.delay(delay);
11317
+ this.logger.info("Starting worker loop", {
11318
+ workerIndex,
11319
+ totalWorkers,
11320
+ delay,
11321
+ workerId,
11322
+ taskCount,
11323
+ pollIntervalMs,
11324
+ immediatePollIntervalMs,
11325
+ concurrencyOptions: this.concurrency
11326
+ });
11314
11327
  while (!this.isShuttingDown) {
11315
11328
  if (this.limiter.activeCount + this.limiter.pendingCount >= this.concurrency.limit) {
11329
+ this.logger.debug("Worker at capacity, waiting", {
11330
+ workerId,
11331
+ concurrencyOptions: this.concurrency,
11332
+ activeCount: this.limiter.activeCount,
11333
+ pendingCount: this.limiter.pendingCount
11334
+ });
11316
11335
  await _Worker.delay(pollIntervalMs);
11317
11336
  continue;
11318
11337
  }
@@ -11326,9 +11345,22 @@ var Worker = class _Worker {
11326
11345
  }
11327
11346
  );
11328
11347
  if (items.length === 0) {
11348
+ this.logger.debug("No items to dequeue", {
11349
+ workerId,
11350
+ concurrencyOptions: this.concurrency,
11351
+ activeCount: this.limiter.activeCount,
11352
+ pendingCount: this.limiter.pendingCount
11353
+ });
11329
11354
  await _Worker.delay(pollIntervalMs);
11330
11355
  continue;
11331
11356
  }
11357
+ this.logger.info("Dequeued items", {
11358
+ workerId,
11359
+ itemCount: items.length,
11360
+ concurrencyOptions: this.concurrency,
11361
+ activeCount: this.limiter.activeCount,
11362
+ pendingCount: this.limiter.pendingCount
11363
+ });
11332
11364
  for (const item of items) {
11333
11365
  this.limiter(() => this.processItem(item, items.length, workerId)).catch(
11334
11366
  (err) => {
@@ -11343,6 +11375,7 @@ var Worker = class _Worker {
11343
11375
  }
11344
11376
  await _Worker.delay(immediatePollIntervalMs);
11345
11377
  }
11378
+ this.logger.info("Worker loop finished", { workerId });
11346
11379
  }
11347
11380
  /**
11348
11381
  * Processes a single item.