@workglow/task-graph 0.2.10 → 0.2.11

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/bun.js CHANGED
@@ -5366,30 +5366,41 @@ class FallbackTaskRunner extends GraphAsTaskRunner {
5366
5366
  }
5367
5367
  const errors = [];
5368
5368
  const totalAttempts = alternatives.length;
5369
- for (let i = 0;i < alternatives.length; i++) {
5370
- if (this.abortController?.signal.aborted) {
5371
- throw new TaskAbortedError("Fallback aborted");
5372
- }
5373
- const alternative = alternatives[i];
5374
- const attemptNumber = i + 1;
5375
- await this.handleProgress(Math.round((i + 0.5) / totalAttempts * 100), `Trying data alternative ${attemptNumber}/${totalAttempts}`);
5376
- try {
5377
- this.resetSubgraph();
5378
- const mergedInput = { ...input, ...alternative };
5379
- const results = await this.task.subGraph.run(mergedInput, {
5380
- parentSignal: this.abortController?.signal,
5381
- outputCache: this.outputCache,
5382
- registry: this.registry
5383
- });
5384
- const mergedOutput = this.task.subGraph.mergeExecuteOutputsToRunOutput(results, this.task.compoundMerge);
5385
- await this.handleProgress(100, `Data alternative ${attemptNumber}/${totalAttempts} succeeded`);
5386
- return await this.executeTaskReactive(input, mergedOutput);
5387
- } catch (error) {
5388
- if (error instanceof TaskAbortedError && !(error instanceof TaskTimeoutError)) {
5389
- throw error;
5369
+ let currentAttemptIndex = 0;
5370
+ const onSubgraphProgress = (innerProgress, message) => {
5371
+ const blended = Math.round((currentAttemptIndex + innerProgress / 100) / totalAttempts * 100);
5372
+ this.handleProgress(blended, message ?? `Data alternative ${currentAttemptIndex + 1}/${totalAttempts}`);
5373
+ };
5374
+ const unsubscribeSubgraphProgress = this.task.subGraph.subscribe("graph_progress", onSubgraphProgress);
5375
+ try {
5376
+ for (let i = 0;i < alternatives.length; i++) {
5377
+ if (this.abortController?.signal.aborted) {
5378
+ throw new TaskAbortedError("Fallback aborted");
5379
+ }
5380
+ currentAttemptIndex = i;
5381
+ const alternative = alternatives[i];
5382
+ const attemptNumber = i + 1;
5383
+ await this.handleProgress(Math.round((i + 0.5) / totalAttempts * 100), `Trying data alternative ${attemptNumber}/${totalAttempts}`);
5384
+ try {
5385
+ this.resetSubgraph();
5386
+ const mergedInput = { ...input, ...alternative };
5387
+ const results = await this.task.subGraph.run(mergedInput, {
5388
+ parentSignal: this.abortController?.signal,
5389
+ outputCache: this.outputCache,
5390
+ registry: this.registry
5391
+ });
5392
+ const mergedOutput = this.task.subGraph.mergeExecuteOutputsToRunOutput(results, this.task.compoundMerge);
5393
+ await this.handleProgress(100, `Data alternative ${attemptNumber}/${totalAttempts} succeeded`);
5394
+ return await this.executeTaskReactive(input, mergedOutput);
5395
+ } catch (error) {
5396
+ if (error instanceof TaskAbortedError && !(error instanceof TaskTimeoutError)) {
5397
+ throw error;
5398
+ }
5399
+ errors.push({ alternative, error });
5390
5400
  }
5391
- errors.push({ alternative, error });
5392
5401
  }
5402
+ } finally {
5403
+ unsubscribeSubgraphProgress();
5393
5404
  }
5394
5405
  throw this.buildAggregateError(errors, "data");
5395
5406
  }
@@ -5730,18 +5741,14 @@ class IteratorTaskRunner extends GraphAsTaskRunner {
5730
5741
  }
5731
5742
  const graphClone = this.cloneGraph(this.task.subGraph);
5732
5743
  this.task.emit("iteration_start", index, iterationCount);
5733
- const taskProgressUnsubs = [];
5734
- for (const t of graphClone.getTasks()) {
5735
- const fn = (p, message) => {
5736
- this.task.emit("iteration_progress", index, iterationCount, p, message);
5737
- if (this.aggregatingParentMapProgress && this.mapPartialIterationCount > 0) {
5738
- this.mapPartialProgress[index] = Math.max(this.mapPartialProgress[index] ?? 0, p);
5739
- this.emitMapParentProgressFromPartials(message);
5740
- }
5741
- };
5742
- t.events.on("progress", fn);
5743
- taskProgressUnsubs.push({ task: t, fn });
5744
- }
5744
+ const onGraphProgress = (p, message) => {
5745
+ this.task.emit("iteration_progress", index, iterationCount, p, message);
5746
+ if (this.aggregatingParentMapProgress && this.mapPartialIterationCount > 0) {
5747
+ this.mapPartialProgress[index] = Math.max(this.mapPartialProgress[index] ?? 0, p);
5748
+ this.emitMapParentProgressFromPartials(message);
5749
+ }
5750
+ };
5751
+ const unsubscribeGraphProgress = graphClone.subscribe("graph_progress", onGraphProgress);
5745
5752
  try {
5746
5753
  const results = await graphClone.run(input, {
5747
5754
  parentSignal: this.abortController?.signal,
@@ -5754,9 +5761,7 @@ class IteratorTaskRunner extends GraphAsTaskRunner {
5754
5761
  }
5755
5762
  return graphClone.mergeExecuteOutputsToRunOutput(results, this.task.compoundMerge);
5756
5763
  } finally {
5757
- for (const { task, fn } of taskProgressUnsubs) {
5758
- task.events.off("progress", fn);
5759
- }
5764
+ unsubscribeGraphProgress();
5760
5765
  if (this.aggregatingParentMapProgress && this.mapPartialIterationCount > 0) {
5761
5766
  this.mapPartialProgress[index] = 100;
5762
5767
  this.emitMapParentProgressFromPartials();
@@ -6422,55 +6427,65 @@ class WhileTask extends GraphAsTask {
6422
6427
  let currentInput = { ...input };
6423
6428
  let currentOutput = {};
6424
6429
  const effectiveMax = arrayAnalysis ? Math.min(this.maxIterations, arrayAnalysis.iterationCount) : this.maxIterations;
6425
- while (this._currentIteration < effectiveMax) {
6426
- if (context.signal?.aborted) {
6427
- break;
6428
- }
6429
- let iterationInput;
6430
- if (arrayAnalysis) {
6431
- iterationInput = {
6432
- ...this.buildIterationInput(currentInput, arrayAnalysis, this._currentIteration),
6433
- _iterationIndex: this._currentIteration
6434
- };
6435
- } else {
6436
- iterationInput = {
6437
- ...currentInput,
6438
- _iterationIndex: this._currentIteration
6439
- };
6440
- }
6441
- const results = await this.subGraph.run(iterationInput, {
6442
- parentSignal: context.signal
6443
- });
6444
- currentOutput = this.subGraph.mergeExecuteOutputsToRunOutput(results, this.compoundMerge);
6445
- let shouldContinue;
6446
- try {
6447
- shouldContinue = condition(currentOutput, this._currentIteration);
6448
- } catch (err) {
6449
- if (err instanceof TaskFailedError) {
6450
- throw err;
6430
+ const onInnerGraphProgress = (innerProgress, innerMessage) => {
6431
+ const blended = Math.min(Math.round((this._currentIteration + innerProgress / 100) / effectiveMax * 100), 99);
6432
+ const message = innerMessage ? `Iteration ${this._currentIteration + 1}/${effectiveMax}: ${innerMessage}` : `Iteration ${this._currentIteration + 1}/${effectiveMax}`;
6433
+ context.updateProgress(blended, message);
6434
+ };
6435
+ const unsubscribeInnerProgress = this.subGraph.subscribe("graph_progress", onInnerGraphProgress);
6436
+ try {
6437
+ while (this._currentIteration < effectiveMax) {
6438
+ if (context.signal?.aborted) {
6439
+ break;
6440
+ }
6441
+ let iterationInput;
6442
+ if (arrayAnalysis) {
6443
+ iterationInput = {
6444
+ ...this.buildIterationInput(currentInput, arrayAnalysis, this._currentIteration),
6445
+ _iterationIndex: this._currentIteration
6446
+ };
6447
+ } else {
6448
+ iterationInput = {
6449
+ ...currentInput,
6450
+ _iterationIndex: this._currentIteration
6451
+ };
6451
6452
  }
6452
- const message = `${this.type}: Condition function threw at iteration ${this._currentIteration}: ${err instanceof Error ? err.message : String(err)}`;
6453
- const wrappedError = new TaskFailedError(message);
6454
- if (err instanceof Error && err.stack) {
6455
- if (wrappedError.stack) {
6456
- wrappedError.stack += `
6453
+ const results = await this.subGraph.run(iterationInput, {
6454
+ parentSignal: context.signal
6455
+ });
6456
+ currentOutput = this.subGraph.mergeExecuteOutputsToRunOutput(results, this.compoundMerge);
6457
+ let shouldContinue;
6458
+ try {
6459
+ shouldContinue = condition(currentOutput, this._currentIteration);
6460
+ } catch (err) {
6461
+ if (err instanceof TaskFailedError) {
6462
+ throw err;
6463
+ }
6464
+ const message = `${this.type}: Condition function threw at iteration ${this._currentIteration}: ${err instanceof Error ? err.message : String(err)}`;
6465
+ const wrappedError = new TaskFailedError(message);
6466
+ if (err instanceof Error && err.stack) {
6467
+ if (wrappedError.stack) {
6468
+ wrappedError.stack += `
6457
6469
  Caused by original error:
6458
6470
  ${err.stack}`;
6459
- } else {
6460
- wrappedError.stack = err.stack;
6471
+ } else {
6472
+ wrappedError.stack = err.stack;
6473
+ }
6461
6474
  }
6475
+ throw wrappedError;
6462
6476
  }
6463
- throw wrappedError;
6464
- }
6465
- if (!shouldContinue) {
6466
- break;
6467
- }
6468
- if (this.chainIterations) {
6469
- currentInput = { ...currentInput, ...currentOutput };
6477
+ if (!shouldContinue) {
6478
+ break;
6479
+ }
6480
+ if (this.chainIterations) {
6481
+ currentInput = { ...currentInput, ...currentOutput };
6482
+ }
6483
+ this._currentIteration++;
6484
+ const progress = Math.min(Math.round(this._currentIteration / effectiveMax * 100), 99);
6485
+ await context.updateProgress(progress, `Completed ${this._currentIteration}/${effectiveMax} iterations`);
6470
6486
  }
6471
- this._currentIteration++;
6472
- const progress = Math.min(Math.round(this._currentIteration / effectiveMax * 100), 99);
6473
- await context.updateProgress(progress, `Completed ${this._currentIteration}/${effectiveMax} iterations`);
6487
+ } finally {
6488
+ unsubscribeInnerProgress();
6474
6489
  }
6475
6490
  return currentOutput;
6476
6491
  }
@@ -6487,40 +6502,50 @@ ${err.stack}`;
6487
6502
  let currentInput = { ...input };
6488
6503
  let currentOutput = {};
6489
6504
  const effectiveMax = arrayAnalysis ? Math.min(this.maxIterations, arrayAnalysis.iterationCount) : this.maxIterations;
6490
- while (this._currentIteration < effectiveMax) {
6491
- if (context.signal?.aborted)
6492
- break;
6493
- let iterationInput;
6494
- if (arrayAnalysis) {
6495
- iterationInput = {
6496
- ...this.buildIterationInput(currentInput, arrayAnalysis, this._currentIteration),
6497
- _iterationIndex: this._currentIteration
6498
- };
6499
- } else {
6500
- iterationInput = {
6501
- ...currentInput,
6502
- _iterationIndex: this._currentIteration
6503
- };
6504
- }
6505
- const results = await this.subGraph.run(iterationInput, {
6506
- parentSignal: context.signal
6507
- });
6508
- currentOutput = this.subGraph.mergeExecuteOutputsToRunOutput(results, this.compoundMerge);
6509
- let shouldContinue;
6510
- try {
6511
- shouldContinue = condition(currentOutput, this._currentIteration);
6512
- } catch (err) {
6513
- throw new TaskFailedError(`${this.type}: Condition function threw at iteration ${this._currentIteration}: ${err instanceof Error ? err.message : String(err)}`);
6514
- }
6515
- if (!shouldContinue) {
6516
- break;
6517
- }
6518
- if (this.chainIterations) {
6519
- currentInput = { ...currentInput, ...currentOutput };
6505
+ const onInnerGraphProgress = (innerProgress, innerMessage) => {
6506
+ const blended = Math.min(Math.round((this._currentIteration + innerProgress / 100) / effectiveMax * 100), 99);
6507
+ const message = innerMessage ? `Iteration ${this._currentIteration + 1}/${effectiveMax}: ${innerMessage}` : `Iteration ${this._currentIteration + 1}/${effectiveMax}`;
6508
+ context.updateProgress(blended, message);
6509
+ };
6510
+ const unsubscribeInnerProgress = this.subGraph.subscribe("graph_progress", onInnerGraphProgress);
6511
+ try {
6512
+ while (this._currentIteration < effectiveMax) {
6513
+ if (context.signal?.aborted)
6514
+ break;
6515
+ let iterationInput;
6516
+ if (arrayAnalysis) {
6517
+ iterationInput = {
6518
+ ...this.buildIterationInput(currentInput, arrayAnalysis, this._currentIteration),
6519
+ _iterationIndex: this._currentIteration
6520
+ };
6521
+ } else {
6522
+ iterationInput = {
6523
+ ...currentInput,
6524
+ _iterationIndex: this._currentIteration
6525
+ };
6526
+ }
6527
+ const results = await this.subGraph.run(iterationInput, {
6528
+ parentSignal: context.signal
6529
+ });
6530
+ currentOutput = this.subGraph.mergeExecuteOutputsToRunOutput(results, this.compoundMerge);
6531
+ let shouldContinue;
6532
+ try {
6533
+ shouldContinue = condition(currentOutput, this._currentIteration);
6534
+ } catch (err) {
6535
+ throw new TaskFailedError(`${this.type}: Condition function threw at iteration ${this._currentIteration}: ${err instanceof Error ? err.message : String(err)}`);
6536
+ }
6537
+ if (!shouldContinue) {
6538
+ break;
6539
+ }
6540
+ if (this.chainIterations) {
6541
+ currentInput = { ...currentInput, ...currentOutput };
6542
+ }
6543
+ this._currentIteration++;
6544
+ const progress = Math.min(Math.round(this._currentIteration / effectiveMax * 100), 99);
6545
+ await context.updateProgress(progress, `Completed ${this._currentIteration}/${effectiveMax} iterations`);
6520
6546
  }
6521
- this._currentIteration++;
6522
- const progress = Math.min(Math.round(this._currentIteration / effectiveMax * 100), 99);
6523
- await context.updateProgress(progress, `Completed ${this._currentIteration}/${effectiveMax} iterations`);
6547
+ } finally {
6548
+ unsubscribeInnerProgress();
6524
6549
  }
6525
6550
  yield { type: "finish", data: currentOutput };
6526
6551
  }
@@ -7606,4 +7631,4 @@ export {
7606
7631
  BROWSER_GRANTS
7607
7632
  };
7608
7633
 
7609
- //# debugId=E0C406676DEAA6C764756E2164756E21
7634
+ //# debugId=4EA2E25DBA8962FA64756E2164756E21