public commit

This commit is contained in:
dswbx
2024-11-16 12:01:47 +01:00
commit 90f80c4280
582 changed files with 49291 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
import { Condition, Flow } from "../../../src/flows";
import { getNamedTask } from "./helper";
const first = getNamedTask("first");
const second = getNamedTask("second");
const fourth = getNamedTask("fourth");
let thirdRuns = 0;
const third = getNamedTask("third", async () => {
thirdRuns++;
if (thirdRuns === 3) {
return true;
}
throw new Error("Third failed");
});
const back = new Flow("back", [first, second, third, fourth]);
back.task(first).asInputFor(second);
back.task(second).asInputFor(third);
back.task(third).asInputFor(second, Condition.error(), 2);
back.task(third).asInputFor(fourth, Condition.success());
export { back };

View File

@@ -0,0 +1,23 @@
import { Condition, Flow } from "../../../src/flows";
import { getNamedTask } from "./helper";
const first = getNamedTask(
"first",
async () => {
//throw new Error("Error");
return {
inner: {
result: 2
}
};
},
1000
);
const second = getNamedTask("second (if match)");
const third = getNamedTask("third (if error)");
const fanout = new Flow("fanout", [first, second, third]);
fanout.task(first).asInputFor(third, Condition.error(), 2);
fanout.task(first).asInputFor(second, Condition.matches("inner.result", 2));
export { fanout };

View File

@@ -0,0 +1,61 @@
import { Task } from "../../../src/flows";
// @todo: polyfill
const Handle = (props: any) => null;
type NodeProps<T> = any;
const Position = { Top: "top", Bottom: "bottom" };
class ExecTask extends Task {
type = "exec";
constructor(
name: string,
params: any,
private fn: () => any
) {
super(name, params);
}
override clone(name: string, params: any) {
return new ExecTask(name, params, this.fn);
}
async execute() {
//console.log("executing", this.name);
return await this.fn();
}
}
/*const ExecNode = ({
data,
isConnectable,
targetPosition = Position.Top,
sourcePosition = Position.Bottom,
selected,
}: NodeProps<ExecTask>) => {
//console.log("data", data, data.hasDelay());
return (
<>
<Handle type="target" position={targetPosition} isConnectable={isConnectable} />
{data?.name} ({selected ? "selected" : "exec"})
<Handle type="source" position={sourcePosition} isConnectable={isConnectable} />
</>
);
};*/
export function getNamedTask(name: string, _func?: () => Promise<any>, delay?: number) {
const func =
_func ??
(async () => {
//console.log(`[DONE] Task: ${name}`);
return true;
});
return new ExecTask(
name,
{
delay
},
func
);
}

View File

@@ -0,0 +1,15 @@
import { Flow } from "../../../src/flows";
import { getNamedTask } from "./helper";
const first = getNamedTask("first");
const second = getNamedTask("second", undefined, 1000);
const third = getNamedTask("third");
const fourth = getNamedTask("fourth");
const fifth = getNamedTask("fifth"); // without connection
const parallel = new Flow("Parallel", [first, second, third, fourth, fifth]);
parallel.task(first).asInputFor(second);
parallel.task(first).asInputFor(third);
parallel.task(third).asInputFor(fourth);
export { parallel };

View File

@@ -0,0 +1,18 @@
import { FetchTask, Flow, LogTask } from "../../../src/flows";
const first = new LogTask("First", { delay: 1000 });
const second = new LogTask("Second", { delay: 1000 });
const third = new LogTask("Long Third", { delay: 2500 });
const fourth = new FetchTask("Fetch Something", {
url: "https://jsonplaceholder.typicode.com/todos/1"
});
const fifth = new LogTask("Task 4", { delay: 500 }); // without connection
const simpleFetch = new Flow("simpleFetch", [first, second, third, fourth, fifth]);
simpleFetch.task(first).asInputFor(second);
simpleFetch.task(first).asInputFor(third);
simpleFetch.task(fourth).asOutputFor(third);
simpleFetch.setRespondingTask(fourth);
export { simpleFetch };