MCPcopy
hub / github.com/Doorman11991/smallcode / executeFlow

Function executeFlow

src/compiled/flows.js:12–44  ·  view source on GitHub ↗
(name, steps, ctx)

Source from the content-addressed store, hash-verified

10const logger_1 = require("./logger");
11const metrics_1 = require("./metrics");
12async function executeFlow(name, steps, ctx) {
13 const completed = [];
14 for (const step of steps) {
15 try {
16 logger_1.logger.info("flow_step_started", { event: name + "." + step.name });
17 await step.action(ctx);
18 completed.push({ step: step.name, compensation: step.compensation });
19 (0, metrics_1.counter)("flow.step_completed", { flow: name, step: step.name });
20 }
21 catch (e) {
22 logger_1.logger.error("flow_step_failed", { event: name + "." + step.name, metadata: { error: e.message } });
23 (0, metrics_1.counter)("flow.step_failed", { flow: name, step: step.name });
24 // Backward compensation in reverse order
25 const compensated = [];
26 for (const c of [...completed].reverse()) {
27 if (!c.compensation)
28 continue;
29 try {
30 await c.compensation(ctx);
31 compensated.push(c.step);
32 logger_1.logger.info("flow_compensated", { event: name + "." + c.step });
33 }
34 catch (compErr) {
35 logger_1.logger.error("flow_compensation_failed", { event: name + "." + c.step, metadata: { error: compErr.message } });
36 // Continue with other compensations even if one fails
37 }
38 }
39 return { ok: false, failed_step: step.name, compensated, error: e.message };
40 }
41 }
42 (0, metrics_1.counter)("flow.completed", { flow: name });
43 return { ok: true, compensated: [] };
44}
45// Flow: improvement_loop
46// ctx must contain: { req, res, auth, client? } for transactional flows
47async function execute_improvement_loop(ctx) {

Callers 1

execute_improvement_loopFunction · 0.70

Calls 2

infoMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected