@camunda8/orchestration-cluster-api 10.0.0-alpha.37 → 10.0.0-alpha.39

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
@@ -9612,10 +9612,12 @@ __export(index_exports, {
9612
9612
  createCamundaClient: () => createCamundaClient,
9613
9613
  createCamundaClientLoose: () => createCamundaClientLoose,
9614
9614
  createCamundaResultClient: () => createCamundaResultClient,
9615
+ createLiveClock: () => createLiveClock,
9615
9616
  default: () => index_default,
9616
9617
  isErr: () => isErr,
9617
9618
  isOk: () => isOk,
9618
9619
  isSdkError: () => isSdkError,
9620
+ liveClock: () => liveClock,
9619
9621
  nextPageRequest: () => nextPageRequest,
9620
9622
  paginate: () => paginate,
9621
9623
  variableNamesFromSchema: () => variableNamesFromSchema
@@ -14239,7 +14241,7 @@ function createLogger(opts = {}) {
14239
14241
  }
14240
14242
 
14241
14243
  // src/runtime/version.ts
14242
- var packageVersion = "10.0.0-alpha.37";
14244
+ var packageVersion = "10.0.0-alpha.39";
14243
14245
 
14244
14246
  // src/runtime/supportLogger.ts
14245
14247
  var NoopSupportLogger = class {
@@ -15271,6 +15273,66 @@ var BackpressureManager = class {
15271
15273
  }
15272
15274
  };
15273
15275
 
15276
+ // src/runtime/clock.ts
15277
+ var SLEW_DIVISOR = 16;
15278
+ var MAX_TIMER_MS = 2147483647;
15279
+ function scheduleLong(ms, onElapsed) {
15280
+ let remaining = Math.max(0, ms);
15281
+ let timer;
15282
+ const step = () => {
15283
+ const slice = Math.min(remaining, MAX_TIMER_MS);
15284
+ remaining -= slice;
15285
+ timer = setTimeout(remaining > 0 ? step : onElapsed, slice);
15286
+ };
15287
+ step();
15288
+ return () => clearTimeout(timer);
15289
+ }
15290
+ function createLiveClock(source = Date.now) {
15291
+ let lastSource = source();
15292
+ let offsetMs = 0;
15293
+ let slewCreditMs = 0;
15294
+ const now2 = () => {
15295
+ const observed = source();
15296
+ if (observed < lastSource) {
15297
+ offsetMs += lastSource - observed;
15298
+ } else if (offsetMs > 0) {
15299
+ slewCreditMs += observed - lastSource;
15300
+ const repay = Math.floor(slewCreditMs / SLEW_DIVISOR);
15301
+ if (repay > 0) {
15302
+ slewCreditMs -= repay * SLEW_DIVISOR;
15303
+ offsetMs -= Math.min(offsetMs, repay);
15304
+ }
15305
+ }
15306
+ lastSource = observed;
15307
+ return observed + offsetMs;
15308
+ };
15309
+ const sleep2 = (ms, signal) => new Promise((resolve, reject) => {
15310
+ if (signal?.aborted) {
15311
+ reject(signal.reason);
15312
+ return;
15313
+ }
15314
+ const cancel = scheduleLong(ms, () => {
15315
+ signal?.removeEventListener("abort", onAbort);
15316
+ resolve();
15317
+ });
15318
+ function onAbort() {
15319
+ cancel();
15320
+ reject(signal?.reason);
15321
+ }
15322
+ signal?.addEventListener("abort", onAbort, { once: true });
15323
+ });
15324
+ const deadline = (ms) => {
15325
+ const controller = new AbortController();
15326
+ const cancel = scheduleLong(
15327
+ ms,
15328
+ () => controller.abort(new DOMException(`Timed out after ${ms}ms`, "TimeoutError"))
15329
+ );
15330
+ return { signal: controller.signal, dispose: cancel };
15331
+ };
15332
+ return { now: now2, sleep: sleep2, deadline };
15333
+ }
15334
+ var liveClock = createLiveClock();
15335
+
15274
15336
  // src/runtime/typedVariables.ts
15275
15337
  var TypedVariablesError = class extends Error {
15276
15338
  constructor(message, options) {
@@ -15504,6 +15566,51 @@ function nextActivationRetryDelayMs(attempt, cfg, rng) {
15504
15566
  return Number.isFinite(cfg.pollIntervalMs) ? Math.max(0, Math.round(cfg.pollIntervalMs)) : 0;
15505
15567
  }
15506
15568
 
15569
+ // src/runtime/workerGracefulStop.ts
15570
+ async function stopWorkerGracefully(deps, opts) {
15571
+ const waitUpToMs = opts?.waitUpToMs ?? 5e3;
15572
+ const checkIntervalMs = opts?.checkIntervalMs ?? 10;
15573
+ deps.haltPolling();
15574
+ const start = liveClock.now();
15575
+ const inFlight = deps.inFlightActivation();
15576
+ if (inFlight) {
15577
+ const budget = liveClock.deadline(waitUpToMs);
15578
+ try {
15579
+ await Promise.race([
15580
+ inFlight,
15581
+ new Promise((_, rej) => {
15582
+ const reject = () => rej(new Error("activation.wait.timeout"));
15583
+ if (budget.signal.aborted) reject();
15584
+ else budget.signal.addEventListener("abort", reject, { once: true });
15585
+ })
15586
+ ]);
15587
+ } catch (e) {
15588
+ if (e && e.message === "activation.wait.timeout") {
15589
+ deps.log.debug("worker.gracefulStop.activationTimeout");
15590
+ }
15591
+ } finally {
15592
+ budget.dispose();
15593
+ }
15594
+ }
15595
+ while (deps.activeJobs() > 0 && liveClock.now() - start < waitUpToMs) {
15596
+ await liveClock.sleep(checkIntervalMs);
15597
+ }
15598
+ const timedOut = deps.activeJobs() > 0;
15599
+ if (timedOut) {
15600
+ const pending = deps.inFlightActivation();
15601
+ if (pending?.cancel) {
15602
+ try {
15603
+ pending.cancel();
15604
+ } catch {
15605
+ }
15606
+ }
15607
+ deps.log.debug("worker.gracefulStop.timeout", { remaining: deps.activeJobs() });
15608
+ } else {
15609
+ deps.log.debug("worker.gracefulStop.done");
15610
+ }
15611
+ return { remainingJobs: deps.activeJobs(), timedOut };
15612
+ }
15613
+
15507
15614
  // src/runtime/workerStartGate.ts
15508
15615
  var WorkerStartGate = class {
15509
15616
  /**
@@ -15650,42 +15757,19 @@ var JobWorker = class {
15650
15757
  * If timeout is reached, falls back to hard stop logic (cancels activation if still pending).
15651
15758
  */
15652
15759
  async stopGracefully(opts) {
15653
- const waitUpToMs = opts?.waitUpToMs ?? 5e3;
15654
- const checkIntervalMs = opts?.checkIntervalMs ?? 10;
15655
- this._stopped = true;
15656
- if (this._pollTimer) clearTimeout(this._pollTimer);
15657
- this._pollTimer = null;
15658
- const start = Date.now();
15659
- if (this._inFlightActivation) {
15660
- try {
15661
- await Promise.race([
15662
- this._inFlightActivation,
15663
- new Promise(
15664
- (_, rej) => setTimeout(() => rej(new Error("activation.wait.timeout")), waitUpToMs)
15665
- )
15666
- ]);
15667
- } catch (e) {
15668
- if (e && e.message === "activation.wait.timeout") {
15669
- this._log.debug("worker.gracefulStop.activationTimeout");
15670
- }
15671
- }
15672
- }
15673
- while (this._activeJobs > 0 && Date.now() - start < waitUpToMs) {
15674
- await new Promise((r) => setTimeout(r, checkIntervalMs));
15675
- }
15676
- const timedOut = this._activeJobs > 0;
15677
- if (timedOut) {
15678
- if (this._inFlightActivation?.cancel) {
15679
- try {
15680
- this._inFlightActivation.cancel();
15681
- } catch {
15682
- }
15683
- }
15684
- this._log.debug("worker.gracefulStop.timeout", { remaining: this._activeJobs });
15685
- } else {
15686
- this._log.debug("worker.gracefulStop.done");
15687
- }
15688
- return { remainingJobs: this._activeJobs, timedOut };
15760
+ return stopWorkerGracefully(
15761
+ {
15762
+ haltPolling: () => {
15763
+ this._stopped = true;
15764
+ if (this._pollTimer) clearTimeout(this._pollTimer);
15765
+ this._pollTimer = null;
15766
+ },
15767
+ activeJobs: () => this._activeJobs,
15768
+ inFlightActivation: () => this._inFlightActivation,
15769
+ log: this._log
15770
+ },
15771
+ opts
15772
+ );
15689
15773
  }
15690
15774
  _scheduleNext(delayMs) {
15691
15775
  if (this._stopped) return;
@@ -15978,42 +16062,19 @@ var ThreadedJobWorker = class {
15978
16062
  this._log.info("worker.stop");
15979
16063
  }
15980
16064
  async stopGracefully(opts) {
15981
- const waitUpToMs = opts?.waitUpToMs ?? 5e3;
15982
- const checkIntervalMs = opts?.checkIntervalMs ?? 10;
15983
- this._stopped = true;
15984
- if (this._pollTimer) clearTimeout(this._pollTimer);
15985
- this._pollTimer = null;
15986
- const start = Date.now();
15987
- if (this._inFlightActivation) {
15988
- try {
15989
- await Promise.race([
15990
- this._inFlightActivation,
15991
- new Promise(
15992
- (_, rej) => setTimeout(() => rej(new Error("activation.wait.timeout")), waitUpToMs)
15993
- )
15994
- ]);
15995
- } catch (e) {
15996
- if (e && e.message === "activation.wait.timeout") {
15997
- this._log.debug("worker.gracefulStop.activationTimeout");
15998
- }
15999
- }
16000
- }
16001
- while (this._activeJobs > 0 && Date.now() - start < waitUpToMs) {
16002
- await new Promise((r) => setTimeout(r, checkIntervalMs));
16003
- }
16004
- const timedOut = this._activeJobs > 0;
16005
- if (timedOut) {
16006
- if (this._inFlightActivation?.cancel) {
16007
- try {
16008
- this._inFlightActivation.cancel();
16009
- } catch {
16010
- }
16011
- }
16012
- this._log.debug("worker.gracefulStop.timeout", { remaining: this._activeJobs });
16013
- } else {
16014
- this._log.debug("worker.gracefulStop.done");
16015
- }
16016
- return { remainingJobs: this._activeJobs, timedOut };
16065
+ return stopWorkerGracefully(
16066
+ {
16067
+ haltPolling: () => {
16068
+ this._stopped = true;
16069
+ if (this._pollTimer) clearTimeout(this._pollTimer);
16070
+ this._pollTimer = null;
16071
+ },
16072
+ activeJobs: () => this._activeJobs,
16073
+ inFlightActivation: () => this._inFlightActivation,
16074
+ log: this._log
16075
+ },
16076
+ opts
16077
+ );
16017
16078
  }
16018
16079
  // ─── Job dispatch ───
16019
16080
  _drainQueue() {
@@ -16696,6 +16757,7 @@ var CamundaClientBase = class {
16696
16757
  _validation = new ValidationManager({ req: "none", res: "none" });
16697
16758
  _log = createLogger();
16698
16759
  _bp;
16760
+ _clock = liveClock;
16699
16761
  /** Registered job workers created via createJobWorker (lifecycle managed by user). */
16700
16762
  _workers = [];
16701
16763
  /** Shared thread pool for all threaded job workers (lazy-initialised on first use). */
@@ -16710,6 +16772,7 @@ var CamundaClientBase = class {
16710
16772
  _overrides = {};
16711
16773
  constructor(opts = {}) {
16712
16774
  if (opts.config) this._overrides = { ...opts.config };
16775
+ this._clock = opts.clock ?? liveClock;
16713
16776
  const { config } = hydrateConfig({ overrides: this._overrides, env: opts.env });
16714
16777
  this._config = deepFreeze2(config);
16715
16778
  this._log = createLogger({
@@ -16782,6 +16845,8 @@ var CamundaClientBase = class {
16782
16845
  this.emitSupportLogPreamble();
16783
16846
  this._bp = new BackpressureManager({
16784
16847
  logger: this._log.scope("bp"),
16848
+ now: () => this._clock.now(),
16849
+ sleep: (ms) => this._clock.sleep(ms),
16785
16850
  config: {
16786
16851
  enabled: this._config.backpressure.enabled,
16787
16852
  observeOnly: this._config.backpressure.observeOnly,
@@ -16984,6 +17049,10 @@ var CamundaClientBase = class {
16984
17049
  _evaluateResponse(raw, opId, buildBackpressureError) {
16985
17050
  return evaluateSdkResponse(raw, { opId, buildBackpressureError });
16986
17051
  }
17052
+ /** Clock backing SDK-internal cadence. The injected one when supplied, else the live clock. */
17053
+ get clock() {
17054
+ return this._clock;
17055
+ }
16987
17056
  /** Public accessor for current backpressure adaptive limiter state (stable) */
16988
17057
  getBackpressureState() {
16989
17058
  try {
@@ -32407,9 +32476,11 @@ var index_default = createCamundaClient;
32407
32476
  createCamundaClient,
32408
32477
  createCamundaClientLoose,
32409
32478
  createCamundaResultClient,
32479
+ createLiveClock,
32410
32480
  isErr,
32411
32481
  isOk,
32412
32482
  isSdkError,
32483
+ liveClock,
32413
32484
  nextPageRequest,
32414
32485
  paginate,
32415
32486
  variableNamesFromSchema