@io-orkes/conductor-javascript 3.0.0 → 3.0.1

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.d.mts CHANGED
@@ -5289,6 +5289,11 @@ declare class TaskRunner {
5289
5289
  get isPaused(): boolean;
5290
5290
  get getOptions(): TaskRunnerOptions;
5291
5291
  private batchPoll;
5292
+ /**
5293
+ * Probed once per process. null = unknown, true = v2 endpoint available,
5294
+ * false = legacy server (no /api/tasks/update-v2 endpoint).
5295
+ */
5296
+ private static updateV2Available;
5292
5297
  updateTaskWithRetry: (task: Task, taskResult: TaskResult) => Promise<Task | undefined>;
5293
5298
  private isValidTask;
5294
5299
  /**
package/dist/index.d.ts CHANGED
@@ -5289,6 +5289,11 @@ declare class TaskRunner {
5289
5289
  get isPaused(): boolean;
5290
5290
  get getOptions(): TaskRunnerOptions;
5291
5291
  private batchPoll;
5292
+ /**
5293
+ * Probed once per process. null = unknown, true = v2 endpoint available,
5294
+ * false = legacy server (no /api/tasks/update-v2 endpoint).
5295
+ */
5296
+ private static updateV2Available;
5292
5297
  updateTaskWithRetry: (task: Task, taskResult: TaskResult) => Promise<Task | undefined>;
5293
5298
  private isValidTask;
5294
5299
  /**
package/dist/index.js CHANGED
@@ -39271,7 +39271,7 @@ var defaultRunnerOptions = {
39271
39271
  concurrency: DEFAULT_CONCURRENCY,
39272
39272
  batchPollingTimeout: DEFAULT_BATCH_POLLING_TIMEOUT
39273
39273
  };
39274
- var TaskRunner = class {
39274
+ var TaskRunner = class _TaskRunner {
39275
39275
  _client;
39276
39276
  worker;
39277
39277
  logger;
@@ -39396,21 +39396,94 @@ var TaskRunner = class {
39396
39396
  throw error;
39397
39397
  }
39398
39398
  };
39399
+ /**
39400
+ * Probed once per process. null = unknown, true = v2 endpoint available,
39401
+ * false = legacy server (no /api/tasks/update-v2 endpoint).
39402
+ */
39403
+ static updateV2Available = null;
39399
39404
  updateTaskWithRetry = async (task, taskResult) => {
39400
39405
  const { workerID } = this.options;
39401
39406
  let retryCount = 0;
39402
39407
  let lastError = null;
39403
39408
  while (retryCount < this.maxRetries) {
39404
39409
  try {
39410
+ if (process.env.CI) {
39411
+ console.log(
39412
+ `[TaskRunner] Submitting task result taskId=${taskResult.taskId} workflowId=${taskResult.workflowInstanceId} taskType=${this.worker.taskDefName} attempt=${retryCount + 1}/${this.maxRetries}`
39413
+ );
39414
+ }
39405
39415
  const updateStart = Date.now();
39406
- const { data: nextTask } = await TaskResource.updateTaskV2({
39407
- client: this._client,
39408
- body: {
39409
- ...taskResult,
39410
- workerId: workerID
39416
+ if (_TaskRunner.updateV2Available === false) {
39417
+ await TaskResource.updateTask({
39418
+ client: this._client,
39419
+ body: { ...taskResult, workerId: workerID },
39420
+ throwOnError: true
39421
+ });
39422
+ const updateDurationMs2 = Date.now() - updateStart;
39423
+ if (process.env.CI) {
39424
+ console.log(
39425
+ `[TaskRunner] Task result accepted (legacy) taskId=${taskResult.taskId} durationMs=${updateDurationMs2}`
39426
+ );
39411
39427
  }
39428
+ await this.eventDispatcher.publishTaskUpdateCompleted({
39429
+ taskType: this.worker.taskDefName,
39430
+ taskId: taskResult.taskId ?? "",
39431
+ workerId: workerID,
39432
+ workflowInstanceId: taskResult.workflowInstanceId,
39433
+ durationMs: updateDurationMs2,
39434
+ timestamp: /* @__PURE__ */ new Date()
39435
+ });
39436
+ return void 0;
39437
+ }
39438
+ const {
39439
+ data: nextTask,
39440
+ error,
39441
+ response
39442
+ } = await TaskResource.updateTaskV2({
39443
+ client: this._client,
39444
+ body: { ...taskResult, workerId: workerID },
39445
+ throwOnError: false
39412
39446
  });
39447
+ if (response.status === 404 || response.status === 405) {
39448
+ if (_TaskRunner.updateV2Available === null) {
39449
+ console.log(
39450
+ `[TaskRunner] /api/tasks/update-v2 not available (HTTP ${response.status}), falling back to legacy /api/tasks endpoint`
39451
+ );
39452
+ _TaskRunner.updateV2Available = false;
39453
+ }
39454
+ await TaskResource.updateTask({
39455
+ client: this._client,
39456
+ body: { ...taskResult, workerId: workerID },
39457
+ throwOnError: true
39458
+ });
39459
+ const updateDurationMs2 = Date.now() - updateStart;
39460
+ if (process.env.CI) {
39461
+ console.log(
39462
+ `[TaskRunner] Task result accepted (legacy) taskId=${taskResult.taskId} durationMs=${updateDurationMs2}`
39463
+ );
39464
+ }
39465
+ await this.eventDispatcher.publishTaskUpdateCompleted({
39466
+ taskType: this.worker.taskDefName,
39467
+ taskId: taskResult.taskId ?? "",
39468
+ workerId: workerID,
39469
+ workflowInstanceId: taskResult.workflowInstanceId,
39470
+ durationMs: updateDurationMs2,
39471
+ timestamp: /* @__PURE__ */ new Date()
39472
+ });
39473
+ return void 0;
39474
+ }
39475
+ if (!response.ok) {
39476
+ throw error ?? new Error(`Task update failed with HTTP ${response.status}`);
39477
+ }
39478
+ if (_TaskRunner.updateV2Available === null) {
39479
+ _TaskRunner.updateV2Available = true;
39480
+ }
39413
39481
  const updateDurationMs = Date.now() - updateStart;
39482
+ if (process.env.CI) {
39483
+ console.log(
39484
+ `[TaskRunner] Task result accepted taskId=${taskResult.taskId} durationMs=${updateDurationMs}`
39485
+ );
39486
+ }
39414
39487
  await this.eventDispatcher.publishTaskUpdateCompleted({
39415
39488
  taskType: this.worker.taskDefName,
39416
39489
  taskId: taskResult.taskId ?? "",
@@ -39427,6 +39500,9 @@ var TaskRunner = class {
39427
39500
  `Error updating task ${taskResult.taskId} on retry ${retryCount + 1}/${this.maxRetries}`,
39428
39501
  error
39429
39502
  );
39503
+ console.log(
39504
+ `[TaskRunner] Task update failed taskId=${taskResult.taskId} attempt=${retryCount + 1}/${this.maxRetries} error=${lastError?.message ?? String(error)}`
39505
+ );
39430
39506
  retryCount++;
39431
39507
  if (retryCount < this.maxRetries) {
39432
39508
  const delayMs = retryCount * 10 * 1e3;