@camunda8/orchestration-cluster-api 10.0.0-alpha.20 → 10.0.0-alpha.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/fp/index.cjs CHANGED
@@ -12967,7 +12967,7 @@ function createLogger(opts = {}) {
12967
12967
  }
12968
12968
 
12969
12969
  // src/runtime/version.ts
12970
- var packageVersion = "10.0.0-alpha.20";
12970
+ var packageVersion = "10.0.0-alpha.21";
12971
12971
 
12972
12972
  // src/runtime/supportLogger.ts
12973
12973
  var NoopSupportLogger = class {
@@ -14205,6 +14205,50 @@ function createVariableSearchFetchPage(params) {
14205
14205
  };
14206
14206
  }
14207
14207
 
14208
+ // src/runtime/workerStartGate.ts
14209
+ var WorkerStartGate = class {
14210
+ /**
14211
+ * @param transportReady Resolves when the worker's transport can service polls.
14212
+ * @param isStopped Reports whether the worker was stopped while the gate was buffering.
14213
+ */
14214
+ constructor(_transportReady, _isStopped) {
14215
+ this._transportReady = _transportReady;
14216
+ this._isStopped = _isStopped;
14217
+ }
14218
+ _transportReady;
14219
+ _isStopped;
14220
+ _requested = false;
14221
+ /** True once a start request has been accepted and not since released. */
14222
+ get requested() {
14223
+ return this._requested;
14224
+ }
14225
+ /**
14226
+ * Record a start request.
14227
+ *
14228
+ * The first accepted request invokes `onReady` once the transport resolves,
14229
+ * and only if the worker has not been stopped in the meantime. If the
14230
+ * transport fails to come up, `onError` is invoked and the gate is released so
14231
+ * a later `start()` can retry.
14232
+ *
14233
+ * @returns `false` when the request was dropped as redundant.
14234
+ */
14235
+ request(onReady, onError) {
14236
+ if (this._requested) return false;
14237
+ this._requested = true;
14238
+ void this._transportReady().then(
14239
+ () => {
14240
+ if (this._isStopped()) return;
14241
+ onReady();
14242
+ },
14243
+ (err) => {
14244
+ this._requested = false;
14245
+ onError(err);
14246
+ }
14247
+ );
14248
+ return true;
14249
+ }
14250
+ };
14251
+
14208
14252
  // src/runtime/jobWorker.ts
14209
14253
  var JobActionReceipt = "JOB_ACTION_RECEIPT";
14210
14254
  var _workerCounter = 0;
@@ -14221,6 +14265,7 @@ var JobWorker = class {
14221
14265
  _inFlightActivation = null;
14222
14266
  // CancelablePromise-like
14223
14267
  _log;
14268
+ _startGate;
14224
14269
  constructor(client2, cfg) {
14225
14270
  this._client = client2;
14226
14271
  this._cfg = {
@@ -14241,6 +14286,10 @@ var JobWorker = class {
14241
14286
  { maxBackoffTimeMs: cfg.maxBackoffTimeMs }
14242
14287
  ]);
14243
14288
  }
14289
+ this._startGate = new WorkerStartGate(
14290
+ () => Promise.resolve(),
14291
+ () => this._stopped
14292
+ );
14244
14293
  if (this._cfg.autoStart) this.start();
14245
14294
  }
14246
14295
  get name() {
@@ -14252,10 +14301,25 @@ var JobWorker = class {
14252
14301
  get stopped() {
14253
14302
  return this._stopped;
14254
14303
  }
14304
+ /**
14305
+ * Begin polling for jobs. Safe to call at any point: the request is buffered
14306
+ * until the transport is ready, and redundant calls (including an explicit
14307
+ * call on an `autoStart` worker) are dropped rather than starting a second
14308
+ * poll loop. Once the worker is stopped, `start()` is a no-op.
14309
+ */
14255
14310
  start() {
14256
14311
  if (this._stopped) return;
14257
- if (this._pollTimer) return;
14312
+ const accepted = this._startGate.request(
14313
+ () => this._beginPolling(),
14314
+ (err) => this._log.error("worker.start.transportError", err)
14315
+ );
14316
+ if (!accepted) {
14317
+ this._log.debug("worker.start.alreadyRequested");
14318
+ return;
14319
+ }
14258
14320
  this._log.info("worker.start");
14321
+ }
14322
+ _beginPolling() {
14259
14323
  const jitterMax = this._cfg.startupJitterMaxSeconds ?? 0;
14260
14324
  if (jitterMax > 0) {
14261
14325
  const jitterMs = Math.floor(Math.random() * jitterMax * 1e3);
@@ -14514,6 +14578,7 @@ var ThreadedJobWorker = class {
14514
14578
  _inFlightActivation = null;
14515
14579
  _log;
14516
14580
  _jobQueue = [];
14581
+ _startGate;
14517
14582
  constructor(client2, pool, cfg) {
14518
14583
  this._client = client2;
14519
14584
  this._pool = pool;
@@ -14530,6 +14595,10 @@ var ThreadedJobWorker = class {
14530
14595
  this._name = cfg.workerName || `threaded-worker-${cfg.jobType}-${++_workerCounter2}`;
14531
14596
  this._log = this._client.logger().scope(`worker:${this._name}`);
14532
14597
  this._pool.onThreadReady = () => this._drainQueue();
14598
+ this._startGate = new WorkerStartGate(
14599
+ () => this._pool.ready,
14600
+ () => this._stopped
14601
+ );
14533
14602
  if (this._cfg.autoStart) this.start();
14534
14603
  }
14535
14604
  get name() {
@@ -14553,10 +14622,25 @@ var ThreadedJobWorker = class {
14553
14622
  get ready() {
14554
14623
  return this._pool.ready;
14555
14624
  }
14625
+ /**
14626
+ * Begin polling for jobs. Safe to call at any point: the request is buffered
14627
+ * until the shared thread pool is ready, and redundant calls (including an
14628
+ * explicit call on an `autoStart` worker) are dropped rather than starting a
14629
+ * second poll loop. Once the worker is stopped, `start()` is a no-op.
14630
+ */
14556
14631
  start() {
14557
14632
  if (this._stopped) return;
14558
- if (this._pollTimer) return;
14633
+ const accepted = this._startGate.request(
14634
+ () => this._beginPolling(),
14635
+ (err) => this._log.error("worker.start.transportError", err)
14636
+ );
14637
+ if (!accepted) {
14638
+ this._log.debug("worker.start.alreadyRequested");
14639
+ return;
14640
+ }
14559
14641
  this._log.info("worker.start");
14642
+ }
14643
+ _beginPolling() {
14560
14644
  const jitterMax = this._cfg.startupJitterMaxSeconds ?? 0;
14561
14645
  if (jitterMax > 0) {
14562
14646
  const jitterMs = Math.floor(Math.random() * jitterMax * 1e3);