chore: sync ops/ds_run.js
This commit is contained in:
1 parent
d62e1d211e
commit
1168b94e67
1 file changed
+47
@@ -0,0 +1,47 @@
|
|||||||
|
// 手动触发海豚流程并轮询: node ds_run.js [dt]
|
||||||
|
const B = "http://192.168.50.177:12345/dolphinscheduler";
|
||||||
|
const PC = 23821961588320, DEF = 23821975260768;
|
||||||
|
let cookie = "";
|
||||||
|
|
||||||
|
async function api(path, form, method) {
|
||||||
|
const opt = { method: method || (form ? "POST" : "GET"), headers: { Cookie: cookie } };
|
||||||
|
if (form) {
|
||||||
|
opt.headers["Content-Type"] = "application/x-www-form-urlencoded";
|
||||||
|
opt.body = new URLSearchParams(form).toString();
|
||||||
|
}
|
||||||
|
const r = await fetch(B + path, opt);
|
||||||
|
const t = await r.text();
|
||||||
|
let j;
|
||||||
|
try { j = JSON.parse(t); } catch { throw new Error(`${path} non-json ${r.status}: ${t.slice(0, 120)}`); }
|
||||||
|
if (j.code !== 0) throw new Error(`${path} -> code=${j.code} msg=${j.msg}`);
|
||||||
|
return j.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
const dt = process.argv[2] || "2026-11-24";
|
||||||
|
const login = await api("/login", { userName: "admin", userPassword: "dolphinscheduler123" });
|
||||||
|
cookie = "sessionId=" + login.sessionId;
|
||||||
|
await api(`/projects/${PC}/executors/start-process-instance`, {
|
||||||
|
processDefinitionCode: DEF, scheduleTime: dt + " 00:00:00", failureStrategy: "CONTINUE", warningType: "NONE", warningGroupId: 0,
|
||||||
|
processInstancePriority: "MEDIUM", workerGroup: "ub1", tenantCode: "czk", environmentCode: -1,
|
||||||
|
startParams: JSON.stringify({ dt }), dryRun: 0, testFlag: 0,
|
||||||
|
});
|
||||||
|
console.log("STARTED dt=" + dt);
|
||||||
|
for (let i = 0; i < 90; i++) {
|
||||||
|
await new Promise(r => setTimeout(r, 15000));
|
||||||
|
const page = await api(`/projects/${PC}/process-instances?pageNo=1&pageSize=3&processDefineCode=${DEF}`);
|
||||||
|
const inst = (page.totalList || [])[0];
|
||||||
|
if (!inst) continue;
|
||||||
|
console.log(`POLL ${i} state=${inst.state} name=${inst.name}`);
|
||||||
|
if (["SUCCESS", "FAILURE", "STOP", "KILL", "PAUSE"].includes(inst.state)) {
|
||||||
|
const tasks = await api(`/projects/${PC}/task-instances?pageNo=1&pageSize=20&processInstanceId=${inst.id}`);
|
||||||
|
for (const t of tasks.totalList || []) console.log(`TASK ${t.name} ${t.state}`);
|
||||||
|
console.log("FINAL " + inst.state);
|
||||||
|
process.exit(inst.state === "SUCCESS" ? 0 : 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log("TIMEOUT");
|
||||||
|
process.exit(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
main().catch(e => { console.error("DS_RUN_FAIL", e.message); process.exit(1); });
|
||||||
Reference in new issue
Block a user