@camunda8/orchestration-cluster-api 10.0.0-alpha.31 → 10.0.0-alpha.32

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.
@@ -6473,7 +6473,7 @@ var init_zod_gen = __esm({
6473
6473
  }));
6474
6474
  zSecretResolveRequest = z.object({
6475
6475
  references: z.array(z.string().max(256).register(z.globalRegistry, {
6476
- description: "A secret reference of the form `camunda.secrets.<name>`."
6476
+ description: "A secret reference of the form `camunda.secrets.<name>`, where `<name>` is a\nnon-empty token of letters, digits, `_` and `-`. A reference outside that form is\nreported in `errors` with `INVALID_REFERENCE` rather than failing the request.\n"
6477
6477
  })).max(20).register(z.globalRegistry, {
6478
6478
  description: "The secret references to resolve, each of the form `camunda.secrets.<name>`.\nDuplicate references are deduplicated by the server and resolved once.\nAt most 20 references may be requested in a single batch.\n"
6479
6479
  })
@@ -9227,11 +9227,17 @@ __export(effect_exports, {
9227
9227
  CamundaValidationError: () => CamundaValidationError2,
9228
9228
  EventualConsistencyTimeout: () => EventualConsistencyTimeout,
9229
9229
  HttpError: () => HttpError,
9230
+ RetryableJobError: () => RetryableJobError,
9231
+ TerminalJobError: () => TerminalJobError,
9232
+ activateJobsStream: () => activateJobsStream,
9230
9233
  createCamundaEffectClient: () => createCamundaEffectClient,
9234
+ createCamundaEffectWorker: () => createCamundaEffectWorker,
9231
9235
  eventually: () => eventually,
9232
9236
  layer: () => layer,
9233
9237
  retryWithBackoff: () => retryWithBackoff,
9234
- withTimeout: () => withTimeout
9238
+ runWorkerLoop: () => runWorkerLoop,
9239
+ withTimeout: () => withTimeout,
9240
+ workerLayer: () => workerLayer
9235
9241
  });
9236
9242
  module.exports = __toCommonJS(effect_exports);
9237
9243
 
@@ -13788,7 +13794,7 @@ function createLogger(opts = {}) {
13788
13794
  }
13789
13795
 
13790
13796
  // src/runtime/version.ts
13791
- var packageVersion = "10.0.0-alpha.31";
13797
+ var packageVersion = "10.0.0-alpha.32";
13792
13798
 
13793
13799
  // src/runtime/supportLogger.ts
13794
13800
  var NoopSupportLogger = class {
@@ -30095,6 +30101,167 @@ var CamundaEffect = class extends import_effect.Context.Service()(
30095
30101
  function layer(options) {
30096
30102
  return import_effect.Layer.sync(CamundaEffect, () => createCamundaEffectClient(options));
30097
30103
  }
30104
+
30105
+ // src/effect-worker.ts
30106
+ var import_effect2 = require("effect");
30107
+ var RetryableJobError = class extends import_effect2.Data.TaggedError("RetryableJobError") {
30108
+ };
30109
+ var TerminalJobError = class extends import_effect2.Data.TaggedError("TerminalJobError") {
30110
+ };
30111
+ var DEFAULT_MAX_JOBS = 10;
30112
+ var DEFAULT_POLL_INTERVAL = "1 second";
30113
+ var DEFAULT_JOB_TIMEOUT = "60 seconds";
30114
+ var DEFAULT_LONGPOLL_TIMEOUT3 = 0;
30115
+ var _workerCounter3 = 0;
30116
+ function toMillis(d) {
30117
+ return import_effect2.Duration.toMillis(import_effect2.Duration.fromInputUnsafe(d));
30118
+ }
30119
+ function activateJobsStream(type, options = {}) {
30120
+ const worker = options.workerName ?? `effect-worker-${type}-${++_workerCounter3}`;
30121
+ const batch = options.maxJobsToActivate ?? DEFAULT_MAX_JOBS;
30122
+ const pollInterval = options.pollInterval ?? DEFAULT_POLL_INTERVAL;
30123
+ const jobTimeout = options.jobTimeout ?? DEFAULT_JOB_TIMEOUT;
30124
+ const requestTimeout = typeof options.requestTimeout === "number" ? options.requestTimeout : options.requestTimeout !== void 0 ? toMillis(options.requestTimeout) : DEFAULT_LONGPOLL_TIMEOUT3;
30125
+ const body = {
30126
+ type,
30127
+ worker,
30128
+ maxJobsToActivate: batch,
30129
+ requestTimeout,
30130
+ timeout: toMillis(jobTimeout),
30131
+ ...options.fetchVariables && options.fetchVariables.length > 0 ? { fetchVariable: [...options.fetchVariables] } : {}
30132
+ };
30133
+ const pollOnce = import_effect2.Effect.gen(function* () {
30134
+ const camunda = yield* CamundaEffect;
30135
+ const result = yield* camunda.activateJobs(body);
30136
+ const jobs = result?.jobs ?? [];
30137
+ if (jobs.length === 0) yield* import_effect2.Effect.sleep(pollInterval);
30138
+ return jobs;
30139
+ });
30140
+ const activation = options.activationRetrySchedule ? import_effect2.Effect.retry(pollOnce, { schedule: options.activationRetrySchedule }) : pollOnce;
30141
+ return import_effect2.Stream.fromIterableEffectRepeat(activation);
30142
+ }
30143
+ function completeJob2(job, vars) {
30144
+ return import_effect2.Effect.gen(function* () {
30145
+ const camunda = yield* CamundaEffect;
30146
+ yield* camunda.completeJob({
30147
+ jobKey: job.jobKey,
30148
+ variables: vars ?? {},
30149
+ ...job.leaseToken != null ? { leaseToken: job.leaseToken } : {}
30150
+ });
30151
+ });
30152
+ }
30153
+ function failJobRetryable(job, error) {
30154
+ return import_effect2.Effect.gen(function* () {
30155
+ const camunda = yield* CamundaEffect;
30156
+ yield* camunda.failJob({
30157
+ jobKey: job.jobKey,
30158
+ errorMessage: error.message,
30159
+ retries: Math.max(0, (job.retries ?? 1) - 1),
30160
+ ...error.retryBackoff !== void 0 ? { retryBackOff: toMillis(error.retryBackoff) } : {},
30161
+ ...error.variables ? { variables: { ...error.variables } } : {},
30162
+ ...job.leaseToken != null ? { leaseToken: job.leaseToken } : {}
30163
+ });
30164
+ });
30165
+ }
30166
+ function raiseIncident(job, error) {
30167
+ return import_effect2.Effect.gen(function* () {
30168
+ const camunda = yield* CamundaEffect;
30169
+ yield* camunda.throwJobError({
30170
+ jobKey: job.jobKey,
30171
+ errorCode: error.code,
30172
+ errorMessage: error.message,
30173
+ ...error.variables ? { variables: { ...error.variables } } : {},
30174
+ ...job.leaseToken != null ? { leaseToken: job.leaseToken } : {}
30175
+ });
30176
+ });
30177
+ }
30178
+ function releaseLease(job) {
30179
+ return import_effect2.Effect.gen(function* () {
30180
+ const camunda = yield* CamundaEffect;
30181
+ yield* camunda.failJob({
30182
+ jobKey: job.jobKey,
30183
+ errorMessage: "worker interrupted; releasing lease for re-activation",
30184
+ retries: job.retries ?? 1,
30185
+ ...job.leaseToken != null ? { leaseToken: job.leaseToken } : {}
30186
+ });
30187
+ }).pipe(import_effect2.Effect.ignore);
30188
+ }
30189
+ function failJobOnDefect(job, defect) {
30190
+ return import_effect2.Effect.gen(function* () {
30191
+ const camunda = yield* CamundaEffect;
30192
+ yield* import_effect2.Effect.logError(
30193
+ `effect-worker: handler for job ${job.jobKey} threw an unexpected defect; failing job with retries - 1`,
30194
+ defect
30195
+ );
30196
+ yield* camunda.failJob({
30197
+ jobKey: job.jobKey,
30198
+ errorMessage: defect instanceof Error ? defect.message : "Handler error",
30199
+ retries: Math.max(0, (job.retries ?? 1) - 1),
30200
+ ...job.leaseToken != null ? { leaseToken: job.leaseToken } : {}
30201
+ });
30202
+ });
30203
+ }
30204
+ function processJob(config, job) {
30205
+ const handled = config.handlerRetrySchedule ? import_effect2.Effect.retry(config.handler(job), {
30206
+ schedule: config.handlerRetrySchedule,
30207
+ while: (e) => e._tag === "RetryableJobError"
30208
+ }) : config.handler(job);
30209
+ return handled.pipe(
30210
+ import_effect2.Effect.flatMap((vars) => completeJob2(job, vars)),
30211
+ import_effect2.Effect.catchTag("RetryableJobError", (e) => failJobRetryable(job, e)),
30212
+ import_effect2.Effect.catchTag("TerminalJobError", (e) => raiseIncident(job, e)),
30213
+ // Interruption is re-raised (not a defect) by `onInterrupt` below; only genuine
30214
+ // handler defects reach here and are converted to a best-effort failJob.
30215
+ import_effect2.Effect.catchDefect((defect) => failJobOnDefect(job, defect)),
30216
+ import_effect2.Effect.onInterrupt(() => releaseLease(job))
30217
+ );
30218
+ }
30219
+ function runWorkerLoop(config) {
30220
+ const concurrency = config.concurrency ?? config.maxJobsToActivate ?? DEFAULT_MAX_JOBS;
30221
+ const maxJobsToActivate = typeof concurrency === "number" ? Math.min(config.maxJobsToActivate ?? DEFAULT_MAX_JOBS, concurrency) : config.maxJobsToActivate;
30222
+ return activateJobsStream(config.type, { ...config, maxJobsToActivate }).pipe(
30223
+ import_effect2.Stream.mapEffect(
30224
+ (job) => (
30225
+ // A per-job acknowledgement failure (completeJob/failJob/throwJobError raising a
30226
+ // `DomainError`) must not tear down the worker: a transient ack outage on one job
30227
+ // would otherwise fail `Stream.runDrain` and stop all processing. Log it and keep
30228
+ // going so `join` ends only on a fatal activation error (its documented contract),
30229
+ // matching the Promise worker which swallows per-job ack failures. Two causes are
30230
+ // re-raised instead of swallowed: a pure interruption (scope close / `interrupt`),
30231
+ // so shutdown and the best-effort lease release in `processJob` still propagate;
30232
+ // and a genuine defect (`die`), so an unexpected bug surfaces rather than hiding —
30233
+ // note handler defects are already converted to a best-effort failJob inside
30234
+ // `processJob`, so only truly unexpected defects reach here.
30235
+ // NOTE: `Effect.catchAll` is avoided deliberately — under the effect 4.0.0-rc it
30236
+ // suppresses `Stream.mapEffect` emission even on the success path; `catchCause`
30237
+ // does not.
30238
+ processJob(config, job).pipe(
30239
+ import_effect2.Effect.catchCause(
30240
+ (cause) => import_effect2.Cause.hasInterruptsOnly(cause) || import_effect2.Cause.hasDies(cause) ? import_effect2.Effect.failCause(cause) : import_effect2.Effect.logError(
30241
+ `effect-worker[${config.type}]: acknowledging job ${job.jobKey} failed; continuing`,
30242
+ cause
30243
+ )
30244
+ )
30245
+ )
30246
+ ),
30247
+ { concurrency }
30248
+ ),
30249
+ import_effect2.Stream.runDrain
30250
+ );
30251
+ }
30252
+ function createCamundaEffectWorker(config) {
30253
+ return import_effect2.Effect.gen(function* () {
30254
+ const fiber = yield* import_effect2.Effect.forkScoped(runWorkerLoop(config));
30255
+ return {
30256
+ type: config.type,
30257
+ join: import_effect2.Fiber.join(fiber),
30258
+ interrupt: import_effect2.Fiber.interrupt(fiber).pipe(import_effect2.Effect.asVoid)
30259
+ };
30260
+ });
30261
+ }
30262
+ function workerLayer(config) {
30263
+ return import_effect2.Layer.effectDiscard(createCamundaEffectWorker(config));
30264
+ }
30098
30265
  // Annotate the CommonJS export names for ESM import in node:
30099
30266
  0 && (module.exports = {
30100
30267
  CamundaEffect,
@@ -30102,10 +30269,16 @@ function layer(options) {
30102
30269
  CamundaValidationError,
30103
30270
  EventualConsistencyTimeout,
30104
30271
  HttpError,
30272
+ RetryableJobError,
30273
+ TerminalJobError,
30274
+ activateJobsStream,
30105
30275
  createCamundaEffectClient,
30276
+ createCamundaEffectWorker,
30106
30277
  eventually,
30107
30278
  layer,
30108
30279
  retryWithBackoff,
30109
- withTimeout
30280
+ runWorkerLoop,
30281
+ withTimeout,
30282
+ workerLayer
30110
30283
  });
30111
30284
  //# sourceMappingURL=index.cjs.map