@workglow/task-graph 0.0.68 → 0.0.70

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/browser.js CHANGED
@@ -11,15 +11,14 @@ import { compileSchema as compileSchema2 } from "@workglow/util";
11
11
  import { areSemanticallyCompatible, EventEmitter } from "@workglow/util";
12
12
 
13
13
  // src/task/TaskTypes.ts
14
- var TaskStatus;
15
- ((TaskStatus2) => {
16
- TaskStatus2["PENDING"] = "PENDING";
17
- TaskStatus2["DISABLED"] = "DISABLED";
18
- TaskStatus2["PROCESSING"] = "PROCESSING";
19
- TaskStatus2["COMPLETED"] = "COMPLETED";
20
- TaskStatus2["ABORTING"] = "ABORTING";
21
- TaskStatus2["FAILED"] = "FAILED";
22
- })(TaskStatus ||= {});
14
+ var TaskStatus = {
15
+ PENDING: "PENDING",
16
+ DISABLED: "DISABLED",
17
+ PROCESSING: "PROCESSING",
18
+ COMPLETED: "COMPLETED",
19
+ ABORTING: "ABORTING",
20
+ FAILED: "FAILED"
21
+ };
23
22
 
24
23
  // src/task-graph/Dataflow.ts
25
24
  var DATAFLOW_ALL_PORTS = "*";
@@ -44,10 +43,10 @@ class Dataflow {
44
43
  }
45
44
  value = undefined;
46
45
  provenance = {};
47
- status = "PENDING" /* PENDING */;
46
+ status = TaskStatus.PENDING;
48
47
  error;
49
48
  reset() {
50
- this.status = "PENDING" /* PENDING */;
49
+ this.status = TaskStatus.PENDING;
51
50
  this.error = undefined;
52
51
  this.value = undefined;
53
52
  this.provenance = {};
@@ -59,22 +58,22 @@ class Dataflow {
59
58
  return;
60
59
  this.status = status;
61
60
  switch (status) {
62
- case "PROCESSING" /* PROCESSING */:
61
+ case TaskStatus.PROCESSING:
63
62
  this.emit("start");
64
63
  break;
65
- case "COMPLETED" /* COMPLETED */:
64
+ case TaskStatus.COMPLETED:
66
65
  this.emit("complete");
67
66
  break;
68
- case "ABORTING" /* ABORTING */:
67
+ case TaskStatus.ABORTING:
69
68
  this.emit("abort");
70
69
  break;
71
- case "PENDING" /* PENDING */:
70
+ case TaskStatus.PENDING:
72
71
  this.emit("reset");
73
72
  break;
74
- case "FAILED" /* FAILED */:
73
+ case TaskStatus.FAILED:
75
74
  this.emit("error", this.error);
76
75
  break;
77
- case "DISABLED" /* DISABLED */:
76
+ case TaskStatus.DISABLED:
78
77
  this.emit("disabled");
79
78
  break;
80
79
  }
@@ -328,7 +327,7 @@ class TaskRunner {
328
327
  }
329
328
  }
330
329
  async runReactive(overrides = {}) {
331
- if (this.task.status === "PROCESSING" /* PROCESSING */) {
330
+ if (this.task.status === TaskStatus.PROCESSING) {
332
331
  return this.task.runOutputData;
333
332
  }
334
333
  this.task.setInput(overrides);
@@ -372,13 +371,13 @@ class TaskRunner {
372
371
  return Object.keys(reactiveResult || {}) >= Object.keys(output || {}) ? reactiveResult : output ?? {};
373
372
  }
374
373
  async handleStart(config = {}) {
375
- if (this.task.status === "PROCESSING" /* PROCESSING */)
374
+ if (this.task.status === TaskStatus.PROCESSING)
376
375
  return;
377
376
  this.nodeProvenance = {};
378
377
  this.running = true;
379
378
  this.task.startedAt = new Date;
380
379
  this.task.progress = 0;
381
- this.task.status = "PROCESSING" /* PROCESSING */;
380
+ this.task.status = TaskStatus.PROCESSING;
382
381
  this.abortController = new AbortController;
383
382
  this.abortController.signal.addEventListener("abort", () => {
384
383
  this.handleAbort();
@@ -404,9 +403,9 @@ class TaskRunner {
404
403
  this.reactiveRunning = true;
405
404
  }
406
405
  async handleAbort() {
407
- if (this.task.status === "ABORTING" /* ABORTING */)
406
+ if (this.task.status === TaskStatus.ABORTING)
408
407
  return;
409
- this.task.status = "ABORTING" /* ABORTING */;
408
+ this.task.status = TaskStatus.ABORTING;
410
409
  this.task.progress = 100;
411
410
  this.task.error = new TaskAbortedError;
412
411
  this.task.emit("abort", this.task.error);
@@ -416,11 +415,11 @@ class TaskRunner {
416
415
  this.reactiveRunning = false;
417
416
  }
418
417
  async handleComplete() {
419
- if (this.task.status === "COMPLETED" /* COMPLETED */)
418
+ if (this.task.status === TaskStatus.COMPLETED)
420
419
  return;
421
420
  this.task.completedAt = new Date;
422
421
  this.task.progress = 100;
423
- this.task.status = "COMPLETED" /* COMPLETED */;
422
+ this.task.status = TaskStatus.COMPLETED;
424
423
  this.abortController = undefined;
425
424
  this.nodeProvenance = {};
426
425
  this.task.emit("complete");
@@ -430,9 +429,9 @@ class TaskRunner {
430
429
  this.reactiveRunning = false;
431
430
  }
432
431
  async handleDisable() {
433
- if (this.task.status === "DISABLED" /* DISABLED */)
432
+ if (this.task.status === TaskStatus.DISABLED)
434
433
  return;
435
- this.task.status = "DISABLED" /* DISABLED */;
434
+ this.task.status = TaskStatus.DISABLED;
436
435
  this.task.progress = 100;
437
436
  this.task.completedAt = new Date;
438
437
  this.abortController = undefined;
@@ -446,14 +445,14 @@ class TaskRunner {
446
445
  async handleError(err) {
447
446
  if (err instanceof TaskAbortedError)
448
447
  return this.handleAbort();
449
- if (this.task.status === "FAILED" /* FAILED */)
448
+ if (this.task.status === TaskStatus.FAILED)
450
449
  return;
451
450
  if (this.task.hasChildren()) {
452
451
  this.task.subGraph.abort();
453
452
  }
454
453
  this.task.completedAt = new Date;
455
454
  this.task.progress = 100;
456
- this.task.status = "FAILED" /* FAILED */;
455
+ this.task.status = TaskStatus.FAILED;
457
456
  this.task.error = err instanceof TaskError ? err : new TaskFailedError(err?.message || "Task failed");
458
457
  this.abortController = undefined;
459
458
  this.nodeProvenance = {};
@@ -541,7 +540,7 @@ class Task {
541
540
  runInputData = {};
542
541
  runOutputData = {};
543
542
  config;
544
- status = "PENDING" /* PENDING */;
543
+ status = TaskStatus.PENDING;
545
544
  progress = 0;
546
545
  createdAt = new Date;
547
546
  startedAt;
@@ -971,24 +970,24 @@ class DependencyBasedScheduler {
971
970
  this.reset();
972
971
  }
973
972
  isTaskReady(task) {
974
- if (task.status === "DISABLED" /* DISABLED */) {
973
+ if (task.status === TaskStatus.DISABLED) {
975
974
  return false;
976
975
  }
977
976
  const sourceDataflows = this.dag.getSourceDataflows(task.config.id);
978
977
  if (sourceDataflows.length > 0) {
979
- const allIncomingDisabled = sourceDataflows.every((df) => df.status === "DISABLED" /* DISABLED */);
978
+ const allIncomingDisabled = sourceDataflows.every((df) => df.status === TaskStatus.DISABLED);
980
979
  if (allIncomingDisabled) {
981
980
  return false;
982
981
  }
983
982
  }
984
- const dependencies = sourceDataflows.filter((df) => df.status !== "DISABLED" /* DISABLED */).map((dataflow) => dataflow.sourceTaskId);
983
+ const dependencies = sourceDataflows.filter((df) => df.status !== TaskStatus.DISABLED).map((dataflow) => dataflow.sourceTaskId);
985
984
  return dependencies.every((dep) => this.completedTasks.has(dep));
986
985
  }
987
986
  async waitForNextTask() {
988
987
  if (this.pendingTasks.size === 0)
989
988
  return null;
990
989
  for (const task of Array.from(this.pendingTasks)) {
991
- if (task.status === "DISABLED" /* DISABLED */) {
990
+ if (task.status === TaskStatus.DISABLED) {
992
991
  this.pendingTasks.delete(task);
993
992
  }
994
993
  }
@@ -1019,7 +1018,7 @@ class DependencyBasedScheduler {
1019
1018
  onTaskCompleted(taskId) {
1020
1019
  this.completedTasks.add(taskId);
1021
1020
  for (const task of Array.from(this.pendingTasks)) {
1022
- if (task.status === "DISABLED" /* DISABLED */) {
1021
+ if (task.status === TaskStatus.DISABLED) {
1023
1022
  this.pendingTasks.delete(task);
1024
1023
  }
1025
1024
  }
@@ -1122,7 +1121,7 @@ class TaskGraphRunner {
1122
1121
  const results = [];
1123
1122
  try {
1124
1123
  for await (const task of this.reactiveScheduler.tasks()) {
1125
- if (task.status === "PENDING" /* PENDING */) {
1124
+ if (task.status === TaskStatus.PENDING) {
1126
1125
  task.resetInputData();
1127
1126
  this.copyInputFromEdgesToNode(task);
1128
1127
  }
@@ -1219,7 +1218,7 @@ class TaskGraphRunner {
1219
1218
  return;
1220
1219
  const dataflows = graph.getTargetDataflows(node.config.id);
1221
1220
  const effectiveStatus = status ?? node.status;
1222
- if (node instanceof ConditionalTask && effectiveStatus === "COMPLETED" /* COMPLETED */) {
1221
+ if (node instanceof ConditionalTask && effectiveStatus === TaskStatus.COMPLETED) {
1223
1222
  const branches = node.config.branches ?? [];
1224
1223
  const portToBranch = new Map;
1225
1224
  for (const branch of branches) {
@@ -1230,9 +1229,9 @@ class TaskGraphRunner {
1230
1229
  const branchId = portToBranch.get(dataflow.sourceTaskPortId);
1231
1230
  if (branchId !== undefined) {
1232
1231
  if (activeBranches.has(branchId)) {
1233
- dataflow.setStatus("COMPLETED" /* COMPLETED */);
1232
+ dataflow.setStatus(TaskStatus.COMPLETED);
1234
1233
  } else {
1235
- dataflow.setStatus("DISABLED" /* DISABLED */);
1234
+ dataflow.setStatus(TaskStatus.DISABLED);
1236
1235
  }
1237
1236
  } else {
1238
1237
  dataflow.setStatus(effectiveStatus);
@@ -1257,22 +1256,22 @@ class TaskGraphRunner {
1257
1256
  while (changed) {
1258
1257
  changed = false;
1259
1258
  for (const task of graph.getTasks()) {
1260
- if (task.status !== "PENDING" /* PENDING */) {
1259
+ if (task.status !== TaskStatus.PENDING) {
1261
1260
  continue;
1262
1261
  }
1263
1262
  const incomingDataflows = graph.getSourceDataflows(task.config.id);
1264
1263
  if (incomingDataflows.length === 0) {
1265
1264
  continue;
1266
1265
  }
1267
- const allDisabled = incomingDataflows.every((df) => df.status === "DISABLED" /* DISABLED */);
1266
+ const allDisabled = incomingDataflows.every((df) => df.status === TaskStatus.DISABLED);
1268
1267
  if (allDisabled) {
1269
- task.status = "DISABLED" /* DISABLED */;
1268
+ task.status = TaskStatus.DISABLED;
1270
1269
  task.progress = 100;
1271
1270
  task.completedAt = new Date;
1272
1271
  task.emit("disabled");
1273
1272
  task.emit("status", task.status);
1274
1273
  graph.getTargetDataflows(task.config.id).forEach((dataflow) => {
1275
- dataflow.setStatus("DISABLED" /* DISABLED */);
1274
+ dataflow.setStatus(TaskStatus.DISABLED);
1276
1275
  });
1277
1276
  this.processScheduler.onTaskCompleted(task.config.id);
1278
1277
  changed = true;
@@ -1301,7 +1300,7 @@ class TaskGraphRunner {
1301
1300
  };
1302
1301
  }
1303
1302
  resetTask(graph, task, runId) {
1304
- task.status = "PENDING" /* PENDING */;
1303
+ task.status = TaskStatus.PENDING;
1305
1304
  task.resetInputData();
1306
1305
  task.runOutputData = {};
1307
1306
  task.error = undefined;
@@ -1378,7 +1377,7 @@ class TaskGraphRunner {
1378
1377
  }
1379
1378
  async handleError(error) {
1380
1379
  await Promise.allSettled(this.graph.getTasks().map(async (task) => {
1381
- if (["PROCESSING" /* PROCESSING */].includes(task.status)) {
1380
+ if (task.status === TaskStatus.PROCESSING) {
1382
1381
  task.abort();
1383
1382
  }
1384
1383
  }));
@@ -1390,7 +1389,7 @@ class TaskGraphRunner {
1390
1389
  }
1391
1390
  async handleAbort() {
1392
1391
  this.graph.getTasks().map(async (task) => {
1393
- if (["PROCESSING" /* PROCESSING */].includes(task.status)) {
1392
+ if (task.status === TaskStatus.PROCESSING) {
1394
1393
  task.abort();
1395
1394
  }
1396
1395
  });
@@ -1402,7 +1401,7 @@ class TaskGraphRunner {
1402
1401
  }
1403
1402
  async handleDisable() {
1404
1403
  await Promise.allSettled(this.graph.getTasks().map(async (task) => {
1405
- if (["PENDING" /* PENDING */].includes(task.status)) {
1404
+ if (task.status === TaskStatus.PENDING) {
1406
1405
  return task.disable();
1407
1406
  }
1408
1407
  }));
@@ -2968,4 +2967,4 @@ export {
2968
2967
  ArrayTask
2969
2968
  };
2970
2969
 
2971
- //# debugId=7754D6F660A291F164756E2164756E21
2970
+ //# debugId=410A2925494B34A264756E2164756E21