@trigger.dev/redis-worker 0.0.0-prerelease-20250503193704 → 0.0.0-process-keep-alive-20250618160907
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 +394 -62
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +34 -8
- package/dist/index.d.ts +34 -8
- package/dist/index.js +394 -62
- package/dist/index.js.map +1 -1
- package/package.json +4 -6
package/dist/index.cjs
CHANGED
|
@@ -8,7 +8,6 @@ var crypto = require('crypto');
|
|
|
8
8
|
require('@trigger.dev/core/v3/utils/flattenAttributes');
|
|
9
9
|
var v3 = require('@trigger.dev/core/v3');
|
|
10
10
|
var serverOnly = require('@trigger.dev/core/v3/serverOnly');
|
|
11
|
-
var promClient = require('prom-client');
|
|
12
11
|
|
|
13
12
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
13
|
|
|
@@ -8743,7 +8742,7 @@ var require_Redis = __commonJS({
|
|
|
8743
8742
|
var lodash_1 = require_lodash3();
|
|
8744
8743
|
var Deque = require_denque();
|
|
8745
8744
|
var debug = (0, utils_1.Debug)("redis");
|
|
8746
|
-
var
|
|
8745
|
+
var Redis4 = class _Redis extends Commander_1.default {
|
|
8747
8746
|
constructor(arg1, arg2, arg3) {
|
|
8748
8747
|
super();
|
|
8749
8748
|
this.status = "wait";
|
|
@@ -9306,12 +9305,12 @@ var require_Redis = __commonJS({
|
|
|
9306
9305
|
}).catch(lodash_1.noop);
|
|
9307
9306
|
}
|
|
9308
9307
|
};
|
|
9309
|
-
|
|
9310
|
-
|
|
9311
|
-
|
|
9312
|
-
(0, applyMixin_1.default)(
|
|
9313
|
-
(0, transaction_1.addTransactionSupport)(
|
|
9314
|
-
exports.default =
|
|
9308
|
+
Redis4.Cluster = cluster_1.default;
|
|
9309
|
+
Redis4.Command = Command_1.default;
|
|
9310
|
+
Redis4.defaultOptions = RedisOptions_1.DEFAULT_REDIS_OPTIONS;
|
|
9311
|
+
(0, applyMixin_1.default)(Redis4, events_1.EventEmitter);
|
|
9312
|
+
(0, transaction_1.addTransactionSupport)(Redis4.prototype);
|
|
9313
|
+
exports.default = Redis4;
|
|
9315
9314
|
}
|
|
9316
9315
|
});
|
|
9317
9316
|
|
|
@@ -9509,6 +9508,39 @@ var SimpleQueue = class {
|
|
|
9509
9508
|
throw e;
|
|
9510
9509
|
}
|
|
9511
9510
|
}
|
|
9511
|
+
async enqueueOnce({
|
|
9512
|
+
id,
|
|
9513
|
+
job,
|
|
9514
|
+
item,
|
|
9515
|
+
attempt,
|
|
9516
|
+
availableAt,
|
|
9517
|
+
visibilityTimeoutMs
|
|
9518
|
+
}) {
|
|
9519
|
+
if (!id) {
|
|
9520
|
+
throw new Error("enqueueOnce requires an id");
|
|
9521
|
+
}
|
|
9522
|
+
try {
|
|
9523
|
+
const score = availableAt ? availableAt.getTime() : Date.now();
|
|
9524
|
+
const deduplicationKey = nanoid();
|
|
9525
|
+
const serializedItem = JSON.stringify({
|
|
9526
|
+
job,
|
|
9527
|
+
item,
|
|
9528
|
+
visibilityTimeoutMs,
|
|
9529
|
+
attempt,
|
|
9530
|
+
deduplicationKey
|
|
9531
|
+
});
|
|
9532
|
+
const result = await this.redis.enqueueItemOnce(`queue`, `items`, id, score, serializedItem);
|
|
9533
|
+
return result === 1;
|
|
9534
|
+
} catch (e) {
|
|
9535
|
+
this.logger.error(`SimpleQueue ${this.name}.enqueueOnce(): error enqueuing`, {
|
|
9536
|
+
queue: this.name,
|
|
9537
|
+
error: e,
|
|
9538
|
+
id,
|
|
9539
|
+
item
|
|
9540
|
+
});
|
|
9541
|
+
throw e;
|
|
9542
|
+
}
|
|
9543
|
+
}
|
|
9512
9544
|
async dequeue(count = 1) {
|
|
9513
9545
|
const now = Date.now();
|
|
9514
9546
|
try {
|
|
@@ -9531,7 +9563,8 @@ var SimpleQueue = class {
|
|
|
9531
9563
|
id,
|
|
9532
9564
|
item: parsedItem,
|
|
9533
9565
|
job: parsedItem.job,
|
|
9534
|
-
timestamp
|
|
9566
|
+
timestamp,
|
|
9567
|
+
availableJobs: Object.keys(this.schema)
|
|
9535
9568
|
});
|
|
9536
9569
|
continue;
|
|
9537
9570
|
}
|
|
@@ -9823,6 +9856,25 @@ var SimpleQueue = class {
|
|
|
9823
9856
|
return 1
|
|
9824
9857
|
`
|
|
9825
9858
|
});
|
|
9859
|
+
this.redis.defineCommand("enqueueItemOnce", {
|
|
9860
|
+
numberOfKeys: 2,
|
|
9861
|
+
lua: `
|
|
9862
|
+
local queue = KEYS[1]
|
|
9863
|
+
local items = KEYS[2]
|
|
9864
|
+
local id = ARGV[1]
|
|
9865
|
+
local score = ARGV[2]
|
|
9866
|
+
local serializedItem = ARGV[3]
|
|
9867
|
+
|
|
9868
|
+
-- Only add if not exists
|
|
9869
|
+
local added = redis.call('HSETNX', items, id, serializedItem)
|
|
9870
|
+
if added == 1 then
|
|
9871
|
+
redis.call('ZADD', queue, 'NX', score, id)
|
|
9872
|
+
return 1
|
|
9873
|
+
else
|
|
9874
|
+
return 0
|
|
9875
|
+
end
|
|
9876
|
+
`
|
|
9877
|
+
});
|
|
9826
9878
|
}
|
|
9827
9879
|
};
|
|
9828
9880
|
|
|
@@ -10179,6 +10231,173 @@ var BaseContext = (
|
|
|
10179
10231
|
);
|
|
10180
10232
|
var ROOT_CONTEXT = new BaseContext();
|
|
10181
10233
|
|
|
10234
|
+
// ../../node_modules/.pnpm/@opentelemetry+api@1.9.0/node_modules/@opentelemetry/api/build/esm/metrics/NoopMeter.js
|
|
10235
|
+
var __extends = /* @__PURE__ */ function() {
|
|
10236
|
+
var extendStatics = function(d, b) {
|
|
10237
|
+
extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d2, b2) {
|
|
10238
|
+
d2.__proto__ = b2;
|
|
10239
|
+
} || function(d2, b2) {
|
|
10240
|
+
for (var p in b2) if (Object.prototype.hasOwnProperty.call(b2, p)) d2[p] = b2[p];
|
|
10241
|
+
};
|
|
10242
|
+
return extendStatics(d, b);
|
|
10243
|
+
};
|
|
10244
|
+
return function(d, b) {
|
|
10245
|
+
if (typeof b !== "function" && b !== null)
|
|
10246
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
10247
|
+
extendStatics(d, b);
|
|
10248
|
+
function __() {
|
|
10249
|
+
this.constructor = d;
|
|
10250
|
+
}
|
|
10251
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
10252
|
+
};
|
|
10253
|
+
}();
|
|
10254
|
+
var NoopMeter = (
|
|
10255
|
+
/** @class */
|
|
10256
|
+
function() {
|
|
10257
|
+
function NoopMeter2() {
|
|
10258
|
+
}
|
|
10259
|
+
NoopMeter2.prototype.createGauge = function(_name, _options) {
|
|
10260
|
+
return NOOP_GAUGE_METRIC;
|
|
10261
|
+
};
|
|
10262
|
+
NoopMeter2.prototype.createHistogram = function(_name, _options) {
|
|
10263
|
+
return NOOP_HISTOGRAM_METRIC;
|
|
10264
|
+
};
|
|
10265
|
+
NoopMeter2.prototype.createCounter = function(_name, _options) {
|
|
10266
|
+
return NOOP_COUNTER_METRIC;
|
|
10267
|
+
};
|
|
10268
|
+
NoopMeter2.prototype.createUpDownCounter = function(_name, _options) {
|
|
10269
|
+
return NOOP_UP_DOWN_COUNTER_METRIC;
|
|
10270
|
+
};
|
|
10271
|
+
NoopMeter2.prototype.createObservableGauge = function(_name, _options) {
|
|
10272
|
+
return NOOP_OBSERVABLE_GAUGE_METRIC;
|
|
10273
|
+
};
|
|
10274
|
+
NoopMeter2.prototype.createObservableCounter = function(_name, _options) {
|
|
10275
|
+
return NOOP_OBSERVABLE_COUNTER_METRIC;
|
|
10276
|
+
};
|
|
10277
|
+
NoopMeter2.prototype.createObservableUpDownCounter = function(_name, _options) {
|
|
10278
|
+
return NOOP_OBSERVABLE_UP_DOWN_COUNTER_METRIC;
|
|
10279
|
+
};
|
|
10280
|
+
NoopMeter2.prototype.addBatchObservableCallback = function(_callback, _observables) {
|
|
10281
|
+
};
|
|
10282
|
+
NoopMeter2.prototype.removeBatchObservableCallback = function(_callback) {
|
|
10283
|
+
};
|
|
10284
|
+
return NoopMeter2;
|
|
10285
|
+
}()
|
|
10286
|
+
);
|
|
10287
|
+
var NoopMetric = (
|
|
10288
|
+
/** @class */
|
|
10289
|
+
/* @__PURE__ */ function() {
|
|
10290
|
+
function NoopMetric2() {
|
|
10291
|
+
}
|
|
10292
|
+
return NoopMetric2;
|
|
10293
|
+
}()
|
|
10294
|
+
);
|
|
10295
|
+
var NoopCounterMetric = (
|
|
10296
|
+
/** @class */
|
|
10297
|
+
function(_super) {
|
|
10298
|
+
__extends(NoopCounterMetric2, _super);
|
|
10299
|
+
function NoopCounterMetric2() {
|
|
10300
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
10301
|
+
}
|
|
10302
|
+
NoopCounterMetric2.prototype.add = function(_value, _attributes) {
|
|
10303
|
+
};
|
|
10304
|
+
return NoopCounterMetric2;
|
|
10305
|
+
}(NoopMetric)
|
|
10306
|
+
);
|
|
10307
|
+
var NoopUpDownCounterMetric = (
|
|
10308
|
+
/** @class */
|
|
10309
|
+
function(_super) {
|
|
10310
|
+
__extends(NoopUpDownCounterMetric2, _super);
|
|
10311
|
+
function NoopUpDownCounterMetric2() {
|
|
10312
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
10313
|
+
}
|
|
10314
|
+
NoopUpDownCounterMetric2.prototype.add = function(_value, _attributes) {
|
|
10315
|
+
};
|
|
10316
|
+
return NoopUpDownCounterMetric2;
|
|
10317
|
+
}(NoopMetric)
|
|
10318
|
+
);
|
|
10319
|
+
var NoopGaugeMetric = (
|
|
10320
|
+
/** @class */
|
|
10321
|
+
function(_super) {
|
|
10322
|
+
__extends(NoopGaugeMetric2, _super);
|
|
10323
|
+
function NoopGaugeMetric2() {
|
|
10324
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
10325
|
+
}
|
|
10326
|
+
NoopGaugeMetric2.prototype.record = function(_value, _attributes) {
|
|
10327
|
+
};
|
|
10328
|
+
return NoopGaugeMetric2;
|
|
10329
|
+
}(NoopMetric)
|
|
10330
|
+
);
|
|
10331
|
+
var NoopHistogramMetric = (
|
|
10332
|
+
/** @class */
|
|
10333
|
+
function(_super) {
|
|
10334
|
+
__extends(NoopHistogramMetric2, _super);
|
|
10335
|
+
function NoopHistogramMetric2() {
|
|
10336
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
10337
|
+
}
|
|
10338
|
+
NoopHistogramMetric2.prototype.record = function(_value, _attributes) {
|
|
10339
|
+
};
|
|
10340
|
+
return NoopHistogramMetric2;
|
|
10341
|
+
}(NoopMetric)
|
|
10342
|
+
);
|
|
10343
|
+
var NoopObservableMetric = (
|
|
10344
|
+
/** @class */
|
|
10345
|
+
function() {
|
|
10346
|
+
function NoopObservableMetric2() {
|
|
10347
|
+
}
|
|
10348
|
+
NoopObservableMetric2.prototype.addCallback = function(_callback) {
|
|
10349
|
+
};
|
|
10350
|
+
NoopObservableMetric2.prototype.removeCallback = function(_callback) {
|
|
10351
|
+
};
|
|
10352
|
+
return NoopObservableMetric2;
|
|
10353
|
+
}()
|
|
10354
|
+
);
|
|
10355
|
+
var NoopObservableCounterMetric = (
|
|
10356
|
+
/** @class */
|
|
10357
|
+
function(_super) {
|
|
10358
|
+
__extends(NoopObservableCounterMetric2, _super);
|
|
10359
|
+
function NoopObservableCounterMetric2() {
|
|
10360
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
10361
|
+
}
|
|
10362
|
+
return NoopObservableCounterMetric2;
|
|
10363
|
+
}(NoopObservableMetric)
|
|
10364
|
+
);
|
|
10365
|
+
var NoopObservableGaugeMetric = (
|
|
10366
|
+
/** @class */
|
|
10367
|
+
function(_super) {
|
|
10368
|
+
__extends(NoopObservableGaugeMetric2, _super);
|
|
10369
|
+
function NoopObservableGaugeMetric2() {
|
|
10370
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
10371
|
+
}
|
|
10372
|
+
return NoopObservableGaugeMetric2;
|
|
10373
|
+
}(NoopObservableMetric)
|
|
10374
|
+
);
|
|
10375
|
+
var NoopObservableUpDownCounterMetric = (
|
|
10376
|
+
/** @class */
|
|
10377
|
+
function(_super) {
|
|
10378
|
+
__extends(NoopObservableUpDownCounterMetric2, _super);
|
|
10379
|
+
function NoopObservableUpDownCounterMetric2() {
|
|
10380
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
10381
|
+
}
|
|
10382
|
+
return NoopObservableUpDownCounterMetric2;
|
|
10383
|
+
}(NoopObservableMetric)
|
|
10384
|
+
);
|
|
10385
|
+
var NOOP_METER = new NoopMeter();
|
|
10386
|
+
var NOOP_COUNTER_METRIC = new NoopCounterMetric();
|
|
10387
|
+
var NOOP_GAUGE_METRIC = new NoopGaugeMetric();
|
|
10388
|
+
var NOOP_HISTOGRAM_METRIC = new NoopHistogramMetric();
|
|
10389
|
+
var NOOP_UP_DOWN_COUNTER_METRIC = new NoopUpDownCounterMetric();
|
|
10390
|
+
var NOOP_OBSERVABLE_COUNTER_METRIC = new NoopObservableCounterMetric();
|
|
10391
|
+
var NOOP_OBSERVABLE_GAUGE_METRIC = new NoopObservableGaugeMetric();
|
|
10392
|
+
var NOOP_OBSERVABLE_UP_DOWN_COUNTER_METRIC = new NoopObservableUpDownCounterMetric();
|
|
10393
|
+
|
|
10394
|
+
// ../../node_modules/.pnpm/@opentelemetry+api@1.9.0/node_modules/@opentelemetry/api/build/esm/metrics/Metric.js
|
|
10395
|
+
var ValueType;
|
|
10396
|
+
(function(ValueType2) {
|
|
10397
|
+
ValueType2[ValueType2["INT"] = 0] = "INT";
|
|
10398
|
+
ValueType2[ValueType2["DOUBLE"] = 1] = "DOUBLE";
|
|
10399
|
+
})(ValueType || (ValueType = {}));
|
|
10400
|
+
|
|
10182
10401
|
// ../../node_modules/.pnpm/@opentelemetry+api@1.9.0/node_modules/@opentelemetry/api/build/esm/context/NoopContextManager.js
|
|
10183
10402
|
var __read3 = function(o, n) {
|
|
10184
10403
|
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
@@ -10541,8 +10760,54 @@ var SpanStatusCode;
|
|
|
10541
10760
|
SpanStatusCode2[SpanStatusCode2["ERROR"] = 2] = "ERROR";
|
|
10542
10761
|
})(SpanStatusCode || (SpanStatusCode = {}));
|
|
10543
10762
|
|
|
10763
|
+
// ../../node_modules/.pnpm/@opentelemetry+api@1.9.0/node_modules/@opentelemetry/api/build/esm/metrics/NoopMeterProvider.js
|
|
10764
|
+
var NoopMeterProvider = (
|
|
10765
|
+
/** @class */
|
|
10766
|
+
function() {
|
|
10767
|
+
function NoopMeterProvider2() {
|
|
10768
|
+
}
|
|
10769
|
+
NoopMeterProvider2.prototype.getMeter = function(_name, _version, _options) {
|
|
10770
|
+
return NOOP_METER;
|
|
10771
|
+
};
|
|
10772
|
+
return NoopMeterProvider2;
|
|
10773
|
+
}()
|
|
10774
|
+
);
|
|
10775
|
+
var NOOP_METER_PROVIDER = new NoopMeterProvider();
|
|
10776
|
+
|
|
10777
|
+
// ../../node_modules/.pnpm/@opentelemetry+api@1.9.0/node_modules/@opentelemetry/api/build/esm/api/metrics.js
|
|
10778
|
+
var API_NAME3 = "metrics";
|
|
10779
|
+
var MetricsAPI = (
|
|
10780
|
+
/** @class */
|
|
10781
|
+
function() {
|
|
10782
|
+
function MetricsAPI2() {
|
|
10783
|
+
}
|
|
10784
|
+
MetricsAPI2.getInstance = function() {
|
|
10785
|
+
if (!this._instance) {
|
|
10786
|
+
this._instance = new MetricsAPI2();
|
|
10787
|
+
}
|
|
10788
|
+
return this._instance;
|
|
10789
|
+
};
|
|
10790
|
+
MetricsAPI2.prototype.setGlobalMeterProvider = function(provider) {
|
|
10791
|
+
return registerGlobal(API_NAME3, provider, DiagAPI.instance());
|
|
10792
|
+
};
|
|
10793
|
+
MetricsAPI2.prototype.getMeterProvider = function() {
|
|
10794
|
+
return getGlobal(API_NAME3) || NOOP_METER_PROVIDER;
|
|
10795
|
+
};
|
|
10796
|
+
MetricsAPI2.prototype.getMeter = function(name, version, options) {
|
|
10797
|
+
return this.getMeterProvider().getMeter(name, version, options);
|
|
10798
|
+
};
|
|
10799
|
+
MetricsAPI2.prototype.disable = function() {
|
|
10800
|
+
unregisterGlobal(API_NAME3, DiagAPI.instance());
|
|
10801
|
+
};
|
|
10802
|
+
return MetricsAPI2;
|
|
10803
|
+
}()
|
|
10804
|
+
);
|
|
10805
|
+
|
|
10806
|
+
// ../../node_modules/.pnpm/@opentelemetry+api@1.9.0/node_modules/@opentelemetry/api/build/esm/metrics-api.js
|
|
10807
|
+
var metrics = MetricsAPI.getInstance();
|
|
10808
|
+
|
|
10544
10809
|
// ../../node_modules/.pnpm/@opentelemetry+api@1.9.0/node_modules/@opentelemetry/api/build/esm/api/trace.js
|
|
10545
|
-
var
|
|
10810
|
+
var API_NAME4 = "trace";
|
|
10546
10811
|
var TraceAPI = (
|
|
10547
10812
|
/** @class */
|
|
10548
10813
|
function() {
|
|
@@ -10564,20 +10829,20 @@ var TraceAPI = (
|
|
|
10564
10829
|
return this._instance;
|
|
10565
10830
|
};
|
|
10566
10831
|
TraceAPI2.prototype.setGlobalTracerProvider = function(provider) {
|
|
10567
|
-
var success = registerGlobal(
|
|
10832
|
+
var success = registerGlobal(API_NAME4, this._proxyTracerProvider, DiagAPI.instance());
|
|
10568
10833
|
if (success) {
|
|
10569
10834
|
this._proxyTracerProvider.setDelegate(provider);
|
|
10570
10835
|
}
|
|
10571
10836
|
return success;
|
|
10572
10837
|
};
|
|
10573
10838
|
TraceAPI2.prototype.getTracerProvider = function() {
|
|
10574
|
-
return getGlobal(
|
|
10839
|
+
return getGlobal(API_NAME4) || this._proxyTracerProvider;
|
|
10575
10840
|
};
|
|
10576
10841
|
TraceAPI2.prototype.getTracer = function(name, version) {
|
|
10577
10842
|
return this.getTracerProvider().getTracer(name, version);
|
|
10578
10843
|
};
|
|
10579
10844
|
TraceAPI2.prototype.disable = function() {
|
|
10580
|
-
unregisterGlobal(
|
|
10845
|
+
unregisterGlobal(API_NAME4, DiagAPI.instance());
|
|
10581
10846
|
this._proxyTracerProvider = new ProxyTracerProvider();
|
|
10582
10847
|
};
|
|
10583
10848
|
return TraceAPI2;
|
|
@@ -10743,6 +11008,8 @@ function validateConcurrency(concurrency) {
|
|
|
10743
11008
|
throw new TypeError("Expected `concurrency` to be a number from 1 and up");
|
|
10744
11009
|
}
|
|
10745
11010
|
}
|
|
11011
|
+
|
|
11012
|
+
// src/worker.ts
|
|
10746
11013
|
var defaultRetrySettings = {
|
|
10747
11014
|
maxAttempts: 12,
|
|
10748
11015
|
factor: 2,
|
|
@@ -10757,6 +11024,7 @@ var Worker = class _Worker {
|
|
|
10757
11024
|
this.options = options;
|
|
10758
11025
|
this.logger = options.logger ?? new logger$1.Logger("Worker", "debug");
|
|
10759
11026
|
this.tracer = options.tracer ?? trace.getTracer(options.name);
|
|
11027
|
+
this.meter = options.meter ?? metrics.getMeter(options.name);
|
|
10760
11028
|
this.shutdownTimeoutMs = options.shutdownTimeoutMs ?? 6e4;
|
|
10761
11029
|
const schema = Object.fromEntries(
|
|
10762
11030
|
Object.entries(this.options.catalog).map(([key, value]) => [key, value.schema])
|
|
@@ -10771,56 +11039,47 @@ var Worker = class _Worker {
|
|
|
10771
11039
|
const { workers = 1, tasksPerWorker = 1, limit = 10 } = options.concurrency ?? {};
|
|
10772
11040
|
this.concurrency = { workers, tasksPerWorker, limit };
|
|
10773
11041
|
this.limiter = pLimit(this.concurrency.limit);
|
|
10774
|
-
this.
|
|
10775
|
-
|
|
10776
|
-
|
|
10777
|
-
|
|
10778
|
-
this.metrics.enqueueDuration = new promClient.Histogram({
|
|
10779
|
-
name: "redis_worker_enqueue_duration_seconds",
|
|
10780
|
-
help: "The duration of enqueue operations",
|
|
10781
|
-
labelNames: ["worker_name", "job_type", "has_available_at"],
|
|
10782
|
-
buckets: [1e-3, 5e-3, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1],
|
|
10783
|
-
registers: [this.metrics.register]
|
|
10784
|
-
});
|
|
10785
|
-
this.metrics.dequeueDuration = new promClient.Histogram({
|
|
10786
|
-
name: "redis_worker_dequeue_duration_seconds",
|
|
10787
|
-
help: "The duration of dequeue operations",
|
|
10788
|
-
labelNames: ["worker_name", "worker_id", "task_count"],
|
|
10789
|
-
buckets: [1e-3, 5e-3, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1],
|
|
10790
|
-
registers: [this.metrics.register]
|
|
10791
|
-
});
|
|
10792
|
-
this.metrics.jobDuration = new promClient.Histogram({
|
|
10793
|
-
name: "redis_worker_job_duration_seconds",
|
|
10794
|
-
help: "The duration of job operations",
|
|
10795
|
-
labelNames: ["worker_name", "worker_id", "batch_size", "job_type", "attempt"],
|
|
10796
|
-
// use different buckets here as jobs can take a while to run
|
|
10797
|
-
buckets: [0.1, 0.25, 0.5, 1, 2.5, 5, 10, 20, 30, 45, 60],
|
|
10798
|
-
registers: [this.metrics.register]
|
|
10799
|
-
});
|
|
10800
|
-
this.metrics.ackDuration = new promClient.Histogram({
|
|
10801
|
-
name: "redis_worker_ack_duration_seconds",
|
|
10802
|
-
help: "The duration of ack operations",
|
|
10803
|
-
labelNames: ["worker_name"],
|
|
10804
|
-
buckets: [1e-3, 5e-3, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1],
|
|
10805
|
-
registers: [this.metrics.register]
|
|
10806
|
-
});
|
|
10807
|
-
this.metrics.redriveDuration = new promClient.Histogram({
|
|
10808
|
-
name: "redis_worker_redrive_duration_seconds",
|
|
10809
|
-
help: "The duration of redrive operations",
|
|
10810
|
-
labelNames: ["worker_name"],
|
|
10811
|
-
buckets: [1e-3, 5e-3, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1],
|
|
10812
|
-
registers: [this.metrics.register]
|
|
10813
|
-
});
|
|
10814
|
-
this.metrics.rescheduleDuration = new promClient.Histogram({
|
|
10815
|
-
name: "redis_worker_reschedule_duration_seconds",
|
|
10816
|
-
help: "The duration of reschedule operations",
|
|
10817
|
-
labelNames: ["worker_name"],
|
|
10818
|
-
buckets: [1e-3, 5e-3, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1],
|
|
10819
|
-
registers: [this.metrics.register]
|
|
11042
|
+
const masterQueueObservableGauge = this.meter.createObservableGauge("redis_worker.queue.size", {
|
|
11043
|
+
description: "The number of items in the queue",
|
|
11044
|
+
unit: "items",
|
|
11045
|
+
valueType: ValueType.INT
|
|
10820
11046
|
});
|
|
11047
|
+
masterQueueObservableGauge.addCallback(this.#updateQueueSizeMetric.bind(this));
|
|
11048
|
+
const deadLetterQueueObservableGauge = this.meter.createObservableGauge(
|
|
11049
|
+
"redis_worker.queue.dead_letter_size",
|
|
11050
|
+
{
|
|
11051
|
+
description: "The number of items in the dead letter queue",
|
|
11052
|
+
unit: "items",
|
|
11053
|
+
valueType: ValueType.INT
|
|
11054
|
+
}
|
|
11055
|
+
);
|
|
11056
|
+
deadLetterQueueObservableGauge.addCallback(this.#updateDeadLetterQueueSizeMetric.bind(this));
|
|
11057
|
+
const concurrencyLimitActiveObservableGauge = this.meter.createObservableGauge(
|
|
11058
|
+
"redis_worker.concurrency.active",
|
|
11059
|
+
{
|
|
11060
|
+
description: "The number of active workers",
|
|
11061
|
+
unit: "workers",
|
|
11062
|
+
valueType: ValueType.INT
|
|
11063
|
+
}
|
|
11064
|
+
);
|
|
11065
|
+
concurrencyLimitActiveObservableGauge.addCallback(
|
|
11066
|
+
this.#updateConcurrencyLimitActiveMetric.bind(this)
|
|
11067
|
+
);
|
|
11068
|
+
const concurrencyLimitPendingObservableGauge = this.meter.createObservableGauge(
|
|
11069
|
+
"redis_worker.concurrency.pending",
|
|
11070
|
+
{
|
|
11071
|
+
description: "The number of pending workers",
|
|
11072
|
+
unit: "workers",
|
|
11073
|
+
valueType: ValueType.INT
|
|
11074
|
+
}
|
|
11075
|
+
);
|
|
11076
|
+
concurrencyLimitPendingObservableGauge.addCallback(
|
|
11077
|
+
this.#updateConcurrencyLimitPendingMetric.bind(this)
|
|
11078
|
+
);
|
|
10821
11079
|
}
|
|
10822
11080
|
subscriber;
|
|
10823
11081
|
tracer;
|
|
11082
|
+
meter;
|
|
10824
11083
|
metrics = {};
|
|
10825
11084
|
queue;
|
|
10826
11085
|
jobs;
|
|
@@ -10831,6 +11090,28 @@ var Worker = class _Worker {
|
|
|
10831
11090
|
shutdownTimeoutMs;
|
|
10832
11091
|
// The p-limit limiter to control overall concurrency.
|
|
10833
11092
|
limiter;
|
|
11093
|
+
async #updateQueueSizeMetric(observableResult) {
|
|
11094
|
+
const queueSize = await this.queue.size();
|
|
11095
|
+
observableResult.observe(queueSize, {
|
|
11096
|
+
worker_name: this.options.name
|
|
11097
|
+
});
|
|
11098
|
+
}
|
|
11099
|
+
async #updateDeadLetterQueueSizeMetric(observableResult) {
|
|
11100
|
+
const deadLetterQueueSize = await this.queue.sizeOfDeadLetterQueue();
|
|
11101
|
+
observableResult.observe(deadLetterQueueSize, {
|
|
11102
|
+
worker_name: this.options.name
|
|
11103
|
+
});
|
|
11104
|
+
}
|
|
11105
|
+
async #updateConcurrencyLimitActiveMetric(observableResult) {
|
|
11106
|
+
observableResult.observe(this.limiter.activeCount, {
|
|
11107
|
+
worker_name: this.options.name
|
|
11108
|
+
});
|
|
11109
|
+
}
|
|
11110
|
+
async #updateConcurrencyLimitPendingMetric(observableResult) {
|
|
11111
|
+
observableResult.observe(this.limiter.pendingCount, {
|
|
11112
|
+
worker_name: this.options.name
|
|
11113
|
+
});
|
|
11114
|
+
}
|
|
10834
11115
|
start() {
|
|
10835
11116
|
const { workers, tasksPerWorker } = this.concurrency;
|
|
10836
11117
|
for (let i = 0; i < workers; i++) {
|
|
@@ -10898,6 +11179,56 @@ var Worker = class _Worker {
|
|
|
10898
11179
|
}
|
|
10899
11180
|
);
|
|
10900
11181
|
}
|
|
11182
|
+
/**
|
|
11183
|
+
* Enqueues a job for processing once. If the job is already in the queue, it will be ignored.
|
|
11184
|
+
* @param options - The enqueue options.
|
|
11185
|
+
* @param options.id - Required unique identifier for the job.
|
|
11186
|
+
* @param options.job - The job type from the worker catalog.
|
|
11187
|
+
* @param options.payload - The job payload that matches the schema defined in the catalog.
|
|
11188
|
+
* @param options.visibilityTimeoutMs - Optional visibility timeout in milliseconds. Defaults to value from catalog.
|
|
11189
|
+
* @param options.availableAt - Optional date when the job should become available for processing. Defaults to now.
|
|
11190
|
+
* @returns A promise that resolves when the job is enqueued.
|
|
11191
|
+
*/
|
|
11192
|
+
enqueueOnce({
|
|
11193
|
+
id,
|
|
11194
|
+
job,
|
|
11195
|
+
payload,
|
|
11196
|
+
visibilityTimeoutMs,
|
|
11197
|
+
availableAt
|
|
11198
|
+
}) {
|
|
11199
|
+
return startSpan(
|
|
11200
|
+
this.tracer,
|
|
11201
|
+
"enqueueOnce",
|
|
11202
|
+
async (span) => {
|
|
11203
|
+
const timeout = visibilityTimeoutMs ?? this.options.catalog[job]?.visibilityTimeoutMs;
|
|
11204
|
+
if (!timeout) {
|
|
11205
|
+
throw new Error(`No visibility timeout found for job ${String(job)} with id ${id}`);
|
|
11206
|
+
}
|
|
11207
|
+
span.setAttribute("job_visibility_timeout_ms", timeout);
|
|
11208
|
+
return this.withHistogram(
|
|
11209
|
+
this.metrics.enqueueDuration,
|
|
11210
|
+
this.queue.enqueueOnce({
|
|
11211
|
+
id,
|
|
11212
|
+
job,
|
|
11213
|
+
item: payload,
|
|
11214
|
+
visibilityTimeoutMs: timeout,
|
|
11215
|
+
availableAt
|
|
11216
|
+
}),
|
|
11217
|
+
{
|
|
11218
|
+
job_type: String(job),
|
|
11219
|
+
has_available_at: availableAt ? "true" : "false"
|
|
11220
|
+
}
|
|
11221
|
+
);
|
|
11222
|
+
},
|
|
11223
|
+
{
|
|
11224
|
+
kind: SpanKind.PRODUCER,
|
|
11225
|
+
attributes: {
|
|
11226
|
+
job_type: String(job),
|
|
11227
|
+
job_id: id
|
|
11228
|
+
}
|
|
11229
|
+
}
|
|
11230
|
+
);
|
|
11231
|
+
}
|
|
10901
11232
|
/**
|
|
10902
11233
|
* Reschedules an existing job to a new available date.
|
|
10903
11234
|
* If the job isn't in the queue, it will be ignored.
|
|
@@ -11082,14 +11413,15 @@ var Worker = class _Worker {
|
|
|
11082
11413
|
});
|
|
11083
11414
|
}
|
|
11084
11415
|
async withHistogram(histogram, promise, labels) {
|
|
11085
|
-
if (!histogram
|
|
11416
|
+
if (!histogram) {
|
|
11086
11417
|
return promise;
|
|
11087
11418
|
}
|
|
11088
|
-
const
|
|
11419
|
+
const start = Date.now();
|
|
11089
11420
|
try {
|
|
11090
11421
|
return await promise;
|
|
11091
11422
|
} finally {
|
|
11092
|
-
|
|
11423
|
+
const duration = (Date.now() - start) / 1e3;
|
|
11424
|
+
histogram.record(duration, { worker_name: this.options.name, ...labels });
|
|
11093
11425
|
}
|
|
11094
11426
|
}
|
|
11095
11427
|
// A simple helper to delay for a given number of milliseconds.
|