droboticflow/tmp/business-mongo-validation.mjs
eust-w 43326d6a5e feat(platform): land workflow, data tooling, and docs updates
Include the accumulated workflow scheduling, run history, subtree rerun, operator UI, deployment, data asset, object storage, database browser, and documentation changes currently in the worktree.
2026-04-24 12:29:46 +08:00

125 lines
3.4 KiB
JavaScript

const base = "http://114.111.24.223:30080";
const stamp = Date.now();
const projectName = `Business Mongo Validation ${stamp}`;
const workflowName = `Business Mongo Write ${stamp}`;
const doc = {
runLabel: `business-mongo-${stamp}`,
source: "workflow",
value: 1,
createdAt: new Date().toISOString(),
};
async function api(path, init = {}) {
const response = await fetch(`${base}${path}`, {
...init,
headers: {
"Content-Type": "application/json",
...(init.headers || {}),
},
});
const text = await response.text();
if (!response.ok) {
throw new Error(`${response.status} ${text}`);
}
return text ? JSON.parse(text) : null;
}
async function main() {
const project = await api("/api/projects", {
method: "POST",
body: JSON.stringify({
name: projectName,
description: "Validate business Mongo write operator",
}),
});
const workflow = await api(`/api/projects/${project.id}/workflows`, {
method: "POST",
body: JSON.stringify({
name: workflowName,
description: "Writes workflow output into business MongoDB",
nodes: [
{
id: "node-source",
type: "operator",
position: { x: 120, y: 180 },
data: {
label: "真实数据源",
category: "IO",
description: "source",
inputs: [],
outputs: [{ id: "out-json", name: "output", type: "json" }],
hyperparams: [{ key: "SOURCE_JSON", value: JSON.stringify([doc]) }],
},
},
{
id: "node-mongo",
type: "operator",
position: { x: 420, y: 180 },
data: {
label: "MongoDB 写入",
category: "DATA",
description: "write business data",
inputs: [{ id: "input", name: "input", type: "json" }],
outputs: [{ id: "result", name: "result", type: "json" }],
hyperparams: [
{ key: "MONGO_COLLECTION", value: "businessWriteValidation" },
{ key: "MONGO_MODE", value: "insert_many" },
{ key: "MONGO_TARGET", value: "business" },
],
},
},
],
edges: [
{
id: "edge-source-mongo",
source: "node-source",
sourceHandle: "out-json",
target: "node-mongo",
targetHandle: "input",
},
],
}),
});
const run = await api(`/api/workflows/${workflow.id}/run`, {
method: "POST",
body: JSON.stringify({ trigger: "manual" }),
});
let latest = null;
for (let attempt = 0; attempt < 90; attempt += 1) {
latest = await api(`/api/runs/${run.id}`);
if (latest.status === "completed" || latest.status === "failed") {
break;
}
await new Promise((resolve) => setTimeout(resolve, 2000));
}
if (!latest || latest.status !== "completed") {
console.log(JSON.stringify({ project, workflow, run: latest }, null, 2));
process.exit(1);
}
const filter = encodeURIComponent(JSON.stringify({ runLabel: doc.runLabel }));
const query = await api(`/api/database/collections/businessWriteValidation/documents?filter=${filter}&limit=10`);
console.log(
JSON.stringify(
{
projectId: project.id,
workflowId: workflow.id,
runId: run.id,
runStatus: latest.status,
query,
},
null,
2,
),
);
}
main().catch((error) => {
console.error(error);
process.exit(1);
});