@trigger.dev/redis-worker 4.0.0-v4-beta.20 → 4.0.0-v4-beta.21

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
@@ -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
 
@@ -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 {
@@ -9823,6 +9855,25 @@ var SimpleQueue = class {
9823
9855
  return 1
9824
9856
  `
9825
9857
  });
9858
+ this.redis.defineCommand("enqueueItemOnce", {
9859
+ numberOfKeys: 2,
9860
+ lua: `
9861
+ local queue = KEYS[1]
9862
+ local items = KEYS[2]
9863
+ local id = ARGV[1]
9864
+ local score = ARGV[2]
9865
+ local serializedItem = ARGV[3]
9866
+
9867
+ -- Only add if not exists
9868
+ local added = redis.call('HSETNX', items, id, serializedItem)
9869
+ if added == 1 then
9870
+ redis.call('ZADD', queue, 'NX', score, id)
9871
+ return 1
9872
+ else
9873
+ return 0
9874
+ end
9875
+ `
9876
+ });
9826
9877
  }
9827
9878
  };
9828
9879
 
@@ -10179,6 +10230,173 @@ var BaseContext = (
10179
10230
  );
10180
10231
  var ROOT_CONTEXT = new BaseContext();
10181
10232
 
10233
+ // ../../node_modules/.pnpm/@opentelemetry+api@1.9.0/node_modules/@opentelemetry/api/build/esm/metrics/NoopMeter.js
10234
+ var __extends = /* @__PURE__ */ function() {
10235
+ var extendStatics = function(d, b) {
10236
+ extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d2, b2) {
10237
+ d2.__proto__ = b2;
10238
+ } || function(d2, b2) {
10239
+ for (var p in b2) if (Object.prototype.hasOwnProperty.call(b2, p)) d2[p] = b2[p];
10240
+ };
10241
+ return extendStatics(d, b);
10242
+ };
10243
+ return function(d, b) {
10244
+ if (typeof b !== "function" && b !== null)
10245
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
10246
+ extendStatics(d, b);
10247
+ function __() {
10248
+ this.constructor = d;
10249
+ }
10250
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
10251
+ };
10252
+ }();
10253
+ var NoopMeter = (
10254
+ /** @class */
10255
+ function() {
10256
+ function NoopMeter2() {
10257
+ }
10258
+ NoopMeter2.prototype.createGauge = function(_name, _options) {
10259
+ return NOOP_GAUGE_METRIC;
10260
+ };
10261
+ NoopMeter2.prototype.createHistogram = function(_name, _options) {
10262
+ return NOOP_HISTOGRAM_METRIC;
10263
+ };
10264
+ NoopMeter2.prototype.createCounter = function(_name, _options) {
10265
+ return NOOP_COUNTER_METRIC;
10266
+ };
10267
+ NoopMeter2.prototype.createUpDownCounter = function(_name, _options) {
10268
+ return NOOP_UP_DOWN_COUNTER_METRIC;
10269
+ };
10270
+ NoopMeter2.prototype.createObservableGauge = function(_name, _options) {
10271
+ return NOOP_OBSERVABLE_GAUGE_METRIC;
10272
+ };
10273
+ NoopMeter2.prototype.createObservableCounter = function(_name, _options) {
10274
+ return NOOP_OBSERVABLE_COUNTER_METRIC;
10275
+ };
10276
+ NoopMeter2.prototype.createObservableUpDownCounter = function(_name, _options) {
10277
+ return NOOP_OBSERVABLE_UP_DOWN_COUNTER_METRIC;
10278
+ };
10279
+ NoopMeter2.prototype.addBatchObservableCallback = function(_callback, _observables) {
10280
+ };
10281
+ NoopMeter2.prototype.removeBatchObservableCallback = function(_callback) {
10282
+ };
10283
+ return NoopMeter2;
10284
+ }()
10285
+ );
10286
+ var NoopMetric = (
10287
+ /** @class */
10288
+ /* @__PURE__ */ function() {
10289
+ function NoopMetric2() {
10290
+ }
10291
+ return NoopMetric2;
10292
+ }()
10293
+ );
10294
+ var NoopCounterMetric = (
10295
+ /** @class */
10296
+ function(_super) {
10297
+ __extends(NoopCounterMetric2, _super);
10298
+ function NoopCounterMetric2() {
10299
+ return _super !== null && _super.apply(this, arguments) || this;
10300
+ }
10301
+ NoopCounterMetric2.prototype.add = function(_value, _attributes) {
10302
+ };
10303
+ return NoopCounterMetric2;
10304
+ }(NoopMetric)
10305
+ );
10306
+ var NoopUpDownCounterMetric = (
10307
+ /** @class */
10308
+ function(_super) {
10309
+ __extends(NoopUpDownCounterMetric2, _super);
10310
+ function NoopUpDownCounterMetric2() {
10311
+ return _super !== null && _super.apply(this, arguments) || this;
10312
+ }
10313
+ NoopUpDownCounterMetric2.prototype.add = function(_value, _attributes) {
10314
+ };
10315
+ return NoopUpDownCounterMetric2;
10316
+ }(NoopMetric)
10317
+ );
10318
+ var NoopGaugeMetric = (
10319
+ /** @class */
10320
+ function(_super) {
10321
+ __extends(NoopGaugeMetric2, _super);
10322
+ function NoopGaugeMetric2() {
10323
+ return _super !== null && _super.apply(this, arguments) || this;
10324
+ }
10325
+ NoopGaugeMetric2.prototype.record = function(_value, _attributes) {
10326
+ };
10327
+ return NoopGaugeMetric2;
10328
+ }(NoopMetric)
10329
+ );
10330
+ var NoopHistogramMetric = (
10331
+ /** @class */
10332
+ function(_super) {
10333
+ __extends(NoopHistogramMetric2, _super);
10334
+ function NoopHistogramMetric2() {
10335
+ return _super !== null && _super.apply(this, arguments) || this;
10336
+ }
10337
+ NoopHistogramMetric2.prototype.record = function(_value, _attributes) {
10338
+ };
10339
+ return NoopHistogramMetric2;
10340
+ }(NoopMetric)
10341
+ );
10342
+ var NoopObservableMetric = (
10343
+ /** @class */
10344
+ function() {
10345
+ function NoopObservableMetric2() {
10346
+ }
10347
+ NoopObservableMetric2.prototype.addCallback = function(_callback) {
10348
+ };
10349
+ NoopObservableMetric2.prototype.removeCallback = function(_callback) {
10350
+ };
10351
+ return NoopObservableMetric2;
10352
+ }()
10353
+ );
10354
+ var NoopObservableCounterMetric = (
10355
+ /** @class */
10356
+ function(_super) {
10357
+ __extends(NoopObservableCounterMetric2, _super);
10358
+ function NoopObservableCounterMetric2() {
10359
+ return _super !== null && _super.apply(this, arguments) || this;
10360
+ }
10361
+ return NoopObservableCounterMetric2;
10362
+ }(NoopObservableMetric)
10363
+ );
10364
+ var NoopObservableGaugeMetric = (
10365
+ /** @class */
10366
+ function(_super) {
10367
+ __extends(NoopObservableGaugeMetric2, _super);
10368
+ function NoopObservableGaugeMetric2() {
10369
+ return _super !== null && _super.apply(this, arguments) || this;
10370
+ }
10371
+ return NoopObservableGaugeMetric2;
10372
+ }(NoopObservableMetric)
10373
+ );
10374
+ var NoopObservableUpDownCounterMetric = (
10375
+ /** @class */
10376
+ function(_super) {
10377
+ __extends(NoopObservableUpDownCounterMetric2, _super);
10378
+ function NoopObservableUpDownCounterMetric2() {
10379
+ return _super !== null && _super.apply(this, arguments) || this;
10380
+ }
10381
+ return NoopObservableUpDownCounterMetric2;
10382
+ }(NoopObservableMetric)
10383
+ );
10384
+ var NOOP_METER = new NoopMeter();
10385
+ var NOOP_COUNTER_METRIC = new NoopCounterMetric();
10386
+ var NOOP_GAUGE_METRIC = new NoopGaugeMetric();
10387
+ var NOOP_HISTOGRAM_METRIC = new NoopHistogramMetric();
10388
+ var NOOP_UP_DOWN_COUNTER_METRIC = new NoopUpDownCounterMetric();
10389
+ var NOOP_OBSERVABLE_COUNTER_METRIC = new NoopObservableCounterMetric();
10390
+ var NOOP_OBSERVABLE_GAUGE_METRIC = new NoopObservableGaugeMetric();
10391
+ var NOOP_OBSERVABLE_UP_DOWN_COUNTER_METRIC = new NoopObservableUpDownCounterMetric();
10392
+
10393
+ // ../../node_modules/.pnpm/@opentelemetry+api@1.9.0/node_modules/@opentelemetry/api/build/esm/metrics/Metric.js
10394
+ var ValueType;
10395
+ (function(ValueType2) {
10396
+ ValueType2[ValueType2["INT"] = 0] = "INT";
10397
+ ValueType2[ValueType2["DOUBLE"] = 1] = "DOUBLE";
10398
+ })(ValueType || (ValueType = {}));
10399
+
10182
10400
  // ../../node_modules/.pnpm/@opentelemetry+api@1.9.0/node_modules/@opentelemetry/api/build/esm/context/NoopContextManager.js
10183
10401
  var __read3 = function(o, n) {
10184
10402
  var m = typeof Symbol === "function" && o[Symbol.iterator];
@@ -10541,8 +10759,54 @@ var SpanStatusCode;
10541
10759
  SpanStatusCode2[SpanStatusCode2["ERROR"] = 2] = "ERROR";
10542
10760
  })(SpanStatusCode || (SpanStatusCode = {}));
10543
10761
 
10762
+ // ../../node_modules/.pnpm/@opentelemetry+api@1.9.0/node_modules/@opentelemetry/api/build/esm/metrics/NoopMeterProvider.js
10763
+ var NoopMeterProvider = (
10764
+ /** @class */
10765
+ function() {
10766
+ function NoopMeterProvider2() {
10767
+ }
10768
+ NoopMeterProvider2.prototype.getMeter = function(_name, _version, _options) {
10769
+ return NOOP_METER;
10770
+ };
10771
+ return NoopMeterProvider2;
10772
+ }()
10773
+ );
10774
+ var NOOP_METER_PROVIDER = new NoopMeterProvider();
10775
+
10776
+ // ../../node_modules/.pnpm/@opentelemetry+api@1.9.0/node_modules/@opentelemetry/api/build/esm/api/metrics.js
10777
+ var API_NAME3 = "metrics";
10778
+ var MetricsAPI = (
10779
+ /** @class */
10780
+ function() {
10781
+ function MetricsAPI2() {
10782
+ }
10783
+ MetricsAPI2.getInstance = function() {
10784
+ if (!this._instance) {
10785
+ this._instance = new MetricsAPI2();
10786
+ }
10787
+ return this._instance;
10788
+ };
10789
+ MetricsAPI2.prototype.setGlobalMeterProvider = function(provider) {
10790
+ return registerGlobal(API_NAME3, provider, DiagAPI.instance());
10791
+ };
10792
+ MetricsAPI2.prototype.getMeterProvider = function() {
10793
+ return getGlobal(API_NAME3) || NOOP_METER_PROVIDER;
10794
+ };
10795
+ MetricsAPI2.prototype.getMeter = function(name, version, options) {
10796
+ return this.getMeterProvider().getMeter(name, version, options);
10797
+ };
10798
+ MetricsAPI2.prototype.disable = function() {
10799
+ unregisterGlobal(API_NAME3, DiagAPI.instance());
10800
+ };
10801
+ return MetricsAPI2;
10802
+ }()
10803
+ );
10804
+
10805
+ // ../../node_modules/.pnpm/@opentelemetry+api@1.9.0/node_modules/@opentelemetry/api/build/esm/metrics-api.js
10806
+ var metrics = MetricsAPI.getInstance();
10807
+
10544
10808
  // ../../node_modules/.pnpm/@opentelemetry+api@1.9.0/node_modules/@opentelemetry/api/build/esm/api/trace.js
10545
- var API_NAME3 = "trace";
10809
+ var API_NAME4 = "trace";
10546
10810
  var TraceAPI = (
10547
10811
  /** @class */
10548
10812
  function() {
@@ -10564,20 +10828,20 @@ var TraceAPI = (
10564
10828
  return this._instance;
10565
10829
  };
10566
10830
  TraceAPI2.prototype.setGlobalTracerProvider = function(provider) {
10567
- var success = registerGlobal(API_NAME3, this._proxyTracerProvider, DiagAPI.instance());
10831
+ var success = registerGlobal(API_NAME4, this._proxyTracerProvider, DiagAPI.instance());
10568
10832
  if (success) {
10569
10833
  this._proxyTracerProvider.setDelegate(provider);
10570
10834
  }
10571
10835
  return success;
10572
10836
  };
10573
10837
  TraceAPI2.prototype.getTracerProvider = function() {
10574
- return getGlobal(API_NAME3) || this._proxyTracerProvider;
10838
+ return getGlobal(API_NAME4) || this._proxyTracerProvider;
10575
10839
  };
10576
10840
  TraceAPI2.prototype.getTracer = function(name, version) {
10577
10841
  return this.getTracerProvider().getTracer(name, version);
10578
10842
  };
10579
10843
  TraceAPI2.prototype.disable = function() {
10580
- unregisterGlobal(API_NAME3, DiagAPI.instance());
10844
+ unregisterGlobal(API_NAME4, DiagAPI.instance());
10581
10845
  this._proxyTracerProvider = new ProxyTracerProvider();
10582
10846
  };
10583
10847
  return TraceAPI2;
@@ -10757,6 +11021,7 @@ var Worker = class _Worker {
10757
11021
  this.options = options;
10758
11022
  this.logger = options.logger ?? new logger$1.Logger("Worker", "debug");
10759
11023
  this.tracer = options.tracer ?? trace.getTracer(options.name);
11024
+ this.meter = options.meter ?? metrics.getMeter(options.name);
10760
11025
  this.shutdownTimeoutMs = options.shutdownTimeoutMs ?? 6e4;
10761
11026
  const schema = Object.fromEntries(
10762
11027
  Object.entries(this.options.catalog).map(([key, value]) => [key, value.schema])
@@ -10771,56 +11036,47 @@ var Worker = class _Worker {
10771
11036
  const { workers = 1, tasksPerWorker = 1, limit = 10 } = options.concurrency ?? {};
10772
11037
  this.concurrency = { workers, tasksPerWorker, limit };
10773
11038
  this.limiter = pLimit(this.concurrency.limit);
10774
- this.metrics.register = options.metrics?.register;
10775
- if (!this.metrics.register) {
10776
- return;
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]
11039
+ const masterQueueObservableGauge = this.meter.createObservableGauge("redis_worker.queue.size", {
11040
+ description: "The number of items in the queue",
11041
+ unit: "items",
11042
+ valueType: ValueType.INT
10820
11043
  });
11044
+ masterQueueObservableGauge.addCallback(this.#updateQueueSizeMetric.bind(this));
11045
+ const deadLetterQueueObservableGauge = this.meter.createObservableGauge(
11046
+ "redis_worker.queue.dead_letter_size",
11047
+ {
11048
+ description: "The number of items in the dead letter queue",
11049
+ unit: "items",
11050
+ valueType: ValueType.INT
11051
+ }
11052
+ );
11053
+ deadLetterQueueObservableGauge.addCallback(this.#updateDeadLetterQueueSizeMetric.bind(this));
11054
+ const concurrencyLimitActiveObservableGauge = this.meter.createObservableGauge(
11055
+ "redis_worker.concurrency.active",
11056
+ {
11057
+ description: "The number of active workers",
11058
+ unit: "workers",
11059
+ valueType: ValueType.INT
11060
+ }
11061
+ );
11062
+ concurrencyLimitActiveObservableGauge.addCallback(
11063
+ this.#updateConcurrencyLimitActiveMetric.bind(this)
11064
+ );
11065
+ const concurrencyLimitPendingObservableGauge = this.meter.createObservableGauge(
11066
+ "redis_worker.concurrency.pending",
11067
+ {
11068
+ description: "The number of pending workers",
11069
+ unit: "workers",
11070
+ valueType: ValueType.INT
11071
+ }
11072
+ );
11073
+ concurrencyLimitPendingObservableGauge.addCallback(
11074
+ this.#updateConcurrencyLimitPendingMetric.bind(this)
11075
+ );
10821
11076
  }
10822
11077
  subscriber;
10823
11078
  tracer;
11079
+ meter;
10824
11080
  metrics = {};
10825
11081
  queue;
10826
11082
  jobs;
@@ -10831,6 +11087,28 @@ var Worker = class _Worker {
10831
11087
  shutdownTimeoutMs;
10832
11088
  // The p-limit limiter to control overall concurrency.
10833
11089
  limiter;
11090
+ async #updateQueueSizeMetric(observableResult) {
11091
+ const queueSize = await this.queue.size();
11092
+ observableResult.observe(queueSize, {
11093
+ worker_name: this.options.name
11094
+ });
11095
+ }
11096
+ async #updateDeadLetterQueueSizeMetric(observableResult) {
11097
+ const deadLetterQueueSize = await this.queue.sizeOfDeadLetterQueue();
11098
+ observableResult.observe(deadLetterQueueSize, {
11099
+ worker_name: this.options.name
11100
+ });
11101
+ }
11102
+ async #updateConcurrencyLimitActiveMetric(observableResult) {
11103
+ observableResult.observe(this.limiter.activeCount, {
11104
+ worker_name: this.options.name
11105
+ });
11106
+ }
11107
+ async #updateConcurrencyLimitPendingMetric(observableResult) {
11108
+ observableResult.observe(this.limiter.pendingCount, {
11109
+ worker_name: this.options.name
11110
+ });
11111
+ }
10834
11112
  start() {
10835
11113
  const { workers, tasksPerWorker } = this.concurrency;
10836
11114
  for (let i = 0; i < workers; i++) {
@@ -10898,6 +11176,56 @@ var Worker = class _Worker {
10898
11176
  }
10899
11177
  );
10900
11178
  }
11179
+ /**
11180
+ * Enqueues a job for processing once. If the job is already in the queue, it will be ignored.
11181
+ * @param options - The enqueue options.
11182
+ * @param options.id - Required unique identifier for the job.
11183
+ * @param options.job - The job type from the worker catalog.
11184
+ * @param options.payload - The job payload that matches the schema defined in the catalog.
11185
+ * @param options.visibilityTimeoutMs - Optional visibility timeout in milliseconds. Defaults to value from catalog.
11186
+ * @param options.availableAt - Optional date when the job should become available for processing. Defaults to now.
11187
+ * @returns A promise that resolves when the job is enqueued.
11188
+ */
11189
+ enqueueOnce({
11190
+ id,
11191
+ job,
11192
+ payload,
11193
+ visibilityTimeoutMs,
11194
+ availableAt
11195
+ }) {
11196
+ return startSpan(
11197
+ this.tracer,
11198
+ "enqueueOnce",
11199
+ async (span) => {
11200
+ const timeout = visibilityTimeoutMs ?? this.options.catalog[job]?.visibilityTimeoutMs;
11201
+ if (!timeout) {
11202
+ throw new Error(`No visibility timeout found for job ${String(job)} with id ${id}`);
11203
+ }
11204
+ span.setAttribute("job_visibility_timeout_ms", timeout);
11205
+ return this.withHistogram(
11206
+ this.metrics.enqueueDuration,
11207
+ this.queue.enqueueOnce({
11208
+ id,
11209
+ job,
11210
+ item: payload,
11211
+ visibilityTimeoutMs: timeout,
11212
+ availableAt
11213
+ }),
11214
+ {
11215
+ job_type: String(job),
11216
+ has_available_at: availableAt ? "true" : "false"
11217
+ }
11218
+ );
11219
+ },
11220
+ {
11221
+ kind: SpanKind.PRODUCER,
11222
+ attributes: {
11223
+ job_type: String(job),
11224
+ job_id: id
11225
+ }
11226
+ }
11227
+ );
11228
+ }
10901
11229
  /**
10902
11230
  * Reschedules an existing job to a new available date.
10903
11231
  * If the job isn't in the queue, it will be ignored.
@@ -11082,14 +11410,15 @@ var Worker = class _Worker {
11082
11410
  });
11083
11411
  }
11084
11412
  async withHistogram(histogram, promise, labels) {
11085
- if (!histogram || !this.metrics.register) {
11413
+ if (!histogram) {
11086
11414
  return promise;
11087
11415
  }
11088
- const end = histogram.startTimer({ worker_name: this.options.name, ...labels });
11416
+ const start = Date.now();
11089
11417
  try {
11090
11418
  return await promise;
11091
11419
  } finally {
11092
- end();
11420
+ const duration = (Date.now() - start) / 1e3;
11421
+ histogram.record(duration, { worker_name: this.options.name, ...labels });
11093
11422
  }
11094
11423
  }
11095
11424
  // A simple helper to delay for a given number of milliseconds.