@cascade-flow/runner 0.2.6 → 0.2.7
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.js +23 -4
- package/dist/index.js.map +3 -3
- package/dist/subprocess-executor.d.ts.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -33,6 +33,7 @@ function getFailurePath(dir, requestId) {
|
|
|
33
33
|
var EMBEDDED_STEP_EXECUTOR = `
|
|
34
34
|
import { pathToFileURL } from "node:url";
|
|
35
35
|
import { join } from "node:path";
|
|
36
|
+
import { AsyncLocalStorage } from "async_hooks";
|
|
36
37
|
|
|
37
38
|
function serializeError(err) {
|
|
38
39
|
if (err instanceof Error) {
|
|
@@ -41,6 +42,9 @@ function serializeError(err) {
|
|
|
41
42
|
return { message: String(err), name: "Error" };
|
|
42
43
|
}
|
|
43
44
|
|
|
45
|
+
// AsyncLocalStorage for checkpoint context
|
|
46
|
+
const checkpointStorage = new AsyncLocalStorage();
|
|
47
|
+
|
|
44
48
|
function createCheckpointFunction(checkpointDir) {
|
|
45
49
|
const checkpointSequences = new Map();
|
|
46
50
|
|
|
@@ -72,9 +76,16 @@ function createCheckpointFunction(checkpointDir) {
|
|
|
72
76
|
return JSON.parse(response.data);
|
|
73
77
|
}
|
|
74
78
|
|
|
75
|
-
// Cache miss: execute function
|
|
79
|
+
// Cache miss: execute function with parent injection
|
|
76
80
|
try {
|
|
77
|
-
const
|
|
81
|
+
const ctx = checkpointStorage.getStore();
|
|
82
|
+
let result = await fn();
|
|
83
|
+
|
|
84
|
+
// Inject parent checkpoint info if in a scope
|
|
85
|
+
if (ctx?.parent && typeof result === "object" && result !== null) {
|
|
86
|
+
result = { _parentCheckpoint: ctx.parent, ...result };
|
|
87
|
+
}
|
|
88
|
+
|
|
78
89
|
await Bun.write(
|
|
79
90
|
join(checkpointDir, "result-" + requestId + ".json"),
|
|
80
91
|
JSON.stringify({ requestId, data: JSON.stringify(result) })
|
|
@@ -96,6 +107,11 @@ function createCheckpointFunction(checkpointDir) {
|
|
|
96
107
|
};
|
|
97
108
|
}
|
|
98
109
|
|
|
110
|
+
// Run with checkpoint context
|
|
111
|
+
function runWithCheckpoint(checkpointFn, fn) {
|
|
112
|
+
return checkpointStorage.run({ checkpoint: checkpointFn }, fn);
|
|
113
|
+
}
|
|
114
|
+
|
|
99
115
|
async function main() {
|
|
100
116
|
try {
|
|
101
117
|
const inputFile = process.env.CF_STEP_INPUT_FILE;
|
|
@@ -123,7 +139,10 @@ async function main() {
|
|
|
123
139
|
throw new Error("Invalid step module at " + stepPath);
|
|
124
140
|
}
|
|
125
141
|
|
|
126
|
-
|
|
142
|
+
// Execute step with checkpoint context
|
|
143
|
+
const result = await runWithCheckpoint(checkpoint, () =>
|
|
144
|
+
stepDef.fn({ dependencies, ctx: reconstructedCtx })
|
|
145
|
+
);
|
|
127
146
|
await Bun.write(outputFile, JSON.stringify(result, null, 2));
|
|
128
147
|
process.exit(0);
|
|
129
148
|
} catch (error) {
|
|
@@ -13163,4 +13182,4 @@ export {
|
|
|
13163
13182
|
calculateWorkflowHash
|
|
13164
13183
|
};
|
|
13165
13184
|
|
|
13166
|
-
//# debugId=
|
|
13185
|
+
//# debugId=1B7890ED6FF9B69B64756E2164756E21
|