@trigger.dev/redis-worker 0.0.0-process-keep-alive-20250620100954 → 0.0.0-process-keep-alive-20250626135929
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 +40 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +40 -2
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -9664,6 +9664,11 @@ var SimpleQueue = class {
|
|
|
9664
9664
|
}
|
|
9665
9665
|
async moveToDeadLetterQueue(id, errorMessage) {
|
|
9666
9666
|
try {
|
|
9667
|
+
this.logger.debug(`SimpleQueue ${this.name}.moveToDeadLetterQueue(): moving item to DLQ`, {
|
|
9668
|
+
queue: this.name,
|
|
9669
|
+
id,
|
|
9670
|
+
errorMessage
|
|
9671
|
+
});
|
|
9667
9672
|
const result = await this.redis.moveToDeadLetterQueue(
|
|
9668
9673
|
`queue`,
|
|
9669
9674
|
`items`,
|
|
@@ -11151,7 +11156,7 @@ var Worker = class _Worker {
|
|
|
11151
11156
|
start() {
|
|
11152
11157
|
const { workers, tasksPerWorker } = this.concurrency;
|
|
11153
11158
|
for (let i = 0; i < workers; i++) {
|
|
11154
|
-
this.workerLoops.push(this.runWorkerLoop(`worker-${nanoid(12)}`, tasksPerWorker));
|
|
11159
|
+
this.workerLoops.push(this.runWorkerLoop(`worker-${nanoid(12)}`, tasksPerWorker, i, workers));
|
|
11155
11160
|
}
|
|
11156
11161
|
this.setupShutdownHandlers();
|
|
11157
11162
|
this.subscriber = createRedisClient(this.options.redisOptions, {
|
|
@@ -11308,11 +11313,30 @@ var Worker = class _Worker {
|
|
|
11308
11313
|
* The main loop that each worker runs. It repeatedly polls for items,
|
|
11309
11314
|
* processes them, and then waits before the next iteration.
|
|
11310
11315
|
*/
|
|
11311
|
-
async runWorkerLoop(workerId, taskCount) {
|
|
11316
|
+
async runWorkerLoop(workerId, taskCount, workerIndex, totalWorkers) {
|
|
11312
11317
|
const pollIntervalMs = this.options.pollIntervalMs ?? 1e3;
|
|
11313
11318
|
const immediatePollIntervalMs = this.options.immediatePollIntervalMs ?? 100;
|
|
11319
|
+
const delayBetweenWorkers = this.options.pollIntervalMs ?? 1e3;
|
|
11320
|
+
const delay = delayBetweenWorkers * (totalWorkers - workerIndex);
|
|
11321
|
+
await _Worker.delay(delay);
|
|
11322
|
+
this.logger.info("Starting worker loop", {
|
|
11323
|
+
workerIndex,
|
|
11324
|
+
totalWorkers,
|
|
11325
|
+
delay,
|
|
11326
|
+
workerId,
|
|
11327
|
+
taskCount,
|
|
11328
|
+
pollIntervalMs,
|
|
11329
|
+
immediatePollIntervalMs,
|
|
11330
|
+
concurrencyOptions: this.concurrency
|
|
11331
|
+
});
|
|
11314
11332
|
while (!this.isShuttingDown) {
|
|
11315
11333
|
if (this.limiter.activeCount + this.limiter.pendingCount >= this.concurrency.limit) {
|
|
11334
|
+
this.logger.debug("Worker at capacity, waiting", {
|
|
11335
|
+
workerId,
|
|
11336
|
+
concurrencyOptions: this.concurrency,
|
|
11337
|
+
activeCount: this.limiter.activeCount,
|
|
11338
|
+
pendingCount: this.limiter.pendingCount
|
|
11339
|
+
});
|
|
11316
11340
|
await _Worker.delay(pollIntervalMs);
|
|
11317
11341
|
continue;
|
|
11318
11342
|
}
|
|
@@ -11326,9 +11350,22 @@ var Worker = class _Worker {
|
|
|
11326
11350
|
}
|
|
11327
11351
|
);
|
|
11328
11352
|
if (items.length === 0) {
|
|
11353
|
+
this.logger.debug("No items to dequeue", {
|
|
11354
|
+
workerId,
|
|
11355
|
+
concurrencyOptions: this.concurrency,
|
|
11356
|
+
activeCount: this.limiter.activeCount,
|
|
11357
|
+
pendingCount: this.limiter.pendingCount
|
|
11358
|
+
});
|
|
11329
11359
|
await _Worker.delay(pollIntervalMs);
|
|
11330
11360
|
continue;
|
|
11331
11361
|
}
|
|
11362
|
+
this.logger.debug("Dequeued items", {
|
|
11363
|
+
workerId,
|
|
11364
|
+
itemCount: items.length,
|
|
11365
|
+
concurrencyOptions: this.concurrency,
|
|
11366
|
+
activeCount: this.limiter.activeCount,
|
|
11367
|
+
pendingCount: this.limiter.pendingCount
|
|
11368
|
+
});
|
|
11332
11369
|
for (const item of items) {
|
|
11333
11370
|
this.limiter(() => this.processItem(item, items.length, workerId)).catch(
|
|
11334
11371
|
(err) => {
|
|
@@ -11343,6 +11380,7 @@ var Worker = class _Worker {
|
|
|
11343
11380
|
}
|
|
11344
11381
|
await _Worker.delay(immediatePollIntervalMs);
|
|
11345
11382
|
}
|
|
11383
|
+
this.logger.info("Worker loop finished", { workerId });
|
|
11346
11384
|
}
|
|
11347
11385
|
/**
|
|
11348
11386
|
* Processes a single item.
|