From 1168b94e67d47491e5b8adfc57ebf41ad9af7f18 Mon Sep 17 00:00:00 2001 From: admin <2775444633@qq.com> Date: Tue, 24 Nov 2026 17:06:08 +0000 Subject: [PATCH] chore: sync ops/ds_run.js --- ops/ds_run.js | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 ops/ds_run.js diff --git a/ops/ds_run.js b/ops/ds_run.js new file mode 100644 index 0000000..208504d --- /dev/null +++ b/ops/ds_run.js @@ -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); }); \ No newline at end of file