From 162d4a904b95eab69c3306858863cb1715127ddf Mon Sep 17 00:00:00 2001 From: admin <2775444633@qq.com> Date: Tue, 24 Nov 2026 18:16:38 +0000 Subject: [PATCH] chore: sync ops/ds_rag_setup.js --- ops/ds_rag_setup.js | 87 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 ops/ds_rag_setup.js diff --git a/ops/ds_rag_setup.js b/ops/ds_rag_setup.js new file mode 100644 index 0000000..1c8c533 --- /dev/null +++ b/ops/ds_rag_setup.js @@ -0,0 +1,87 @@ +// 海豚挂载 RAG 每日同步: node ops/ds_rag_setup.js (幂等) +const B = "http://192.168.50.177:12345/dolphinscheduler"; +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; +} + +const SCRIPT = `RESP=$(curl -s -m 570 -X POST http://192.168.50.176:8088/v1/workflows/run \\ + -H "Authorization: Bearer app-Dhm2S4bGnFH4ERr8Z1FcB06a" -H "Content-Type: application/json" \\ + -d '{"inputs":{"force":""},"response_mode":"blocking","user":"ds-rag"}') +echo "$RESP" | python3 -c 'import json,sys; j=json.load(sys.stdin); d=j.get("data",{}); print("RAG_STATUS", d.get("status"), str(d.get("outputs"))[:300]); sys.exit(0 if d.get("status")=="succeeded" else 1)' +`; + +async function main() { + const login = await api("/login", { userName: "admin", userPassword: "dolphinscheduler123" }); + cookie = "sessionId=" + login.sessionId; + console.log("LOGIN_OK"); + + const projects = await api("/projects/list"); + const proj = projects.find(p => p.name === "mini-erp-warehouse"); + if (!proj) throw new Error("project mini-erp-warehouse missing, run ds_setup.js first"); + const pc = proj.code; + + const codes = await api(`/projects/${pc}/task-definition/gen-task-codes?genNum=1`); + const taskDefinitionJson = JSON.stringify([{ + code: codes[0], name: "rag_qdrant_sync", version: 1, description: "Gitea docs -> bge-m3 -> Qdrant 每日增量", delayTime: 0, + taskType: "SHELL", taskParams: JSON.stringify({ localParams: [], rawScript: SCRIPT, resourceList: [] }), + flag: "YES", isCache: "NO", taskPriority: "MEDIUM", workerGroup: "ub1", + taskGroupId: 0, taskGroupPriority: 0, + failRetryTimes: 2, failRetryInterval: 2, timeoutFlag: "CLOSE", timeoutNotifyStrategy: "WARN", + timeout: 0, environmentCode: -1, taskExecuteType: "BATCH", + }]); + const taskRelationJson = JSON.stringify([{ name: "", preTaskCode: 0, preTaskVersion: 0, postTaskCode: codes[0], postTaskVersion: 1 }]); + const locations = JSON.stringify({ [String(codes[0])]: { x: 120, y: 120 } }); + const defForm = { + name: "mini_erp_rag_daily", description: "业务文档向量化每日增量同步(幂等+删除清理)", + globalParams: "[]", locations, timeout: 0, taskRelationJson, taskDefinitionJson, executionType: "PARALLEL", + }; + + let defCode; + const existingResp = await api(`/projects/${pc}/process-definition/query-by-name?name=mini_erp_rag_daily`).catch(() => null); + const existing = existingResp && (existingResp.processDefinition || existingResp); + if (existing && existing.code) { + defCode = existing.code; + if (existing.releaseState === "ONLINE") await api(`/projects/${pc}/process-definition/${defCode}/release`, { releaseState: "OFFLINE" }); + await api(`/projects/${pc}/process-definition/${defCode}`, defForm, "PUT"); + console.log("WORKFLOW_UPDATED", defCode); + } else { + const created = await api(`/projects/${pc}/process-definition`, defForm); + defCode = created.code || created; + console.log("WORKFLOW_CREATED", defCode); + } + await api(`/projects/${pc}/process-definition/${defCode}/release`, { releaseState: "ONLINE" }); + console.log("WORKFLOW_ONLINE", defCode); + + const schedList = await api(`/projects/${pc}/schedules?pageNo=1&pageSize=10&processDefinitionId=${defCode}`); + let sched = (Array.isArray(schedList) ? schedList : schedList.totalList || []).find(s => s.processDefinitionCode === defCode); + const scheduleJson = JSON.stringify({ + startTime: "2026-11-25 00:00:00", endTime: "2126-11-25 00:00:00", + crontab: "0 10 3 * * ? *", timezoneId: "Asia/Shanghai", + }); + if (!sched) { + sched = await api(`/projects/${pc}/schedules`, { + processDefinitionCode: defCode, schedule: scheduleJson, + warningType: "NONE", warningGroupId: 0, failureStrategy: "CONTINUE", + workerGroup: "ub1", tenantCode: "czk", environmentCode: -1, processInstancePriority: "MEDIUM", + }); + console.log("SCHEDULE_CREATED", sched.id || sched); + } else console.log("SCHEDULE_EXISTS", sched.id); + const sid = sched.id || sched; + await api(`/projects/${pc}/schedules/${sid}/online`, {}); + console.log("SCHEDULE_ONLINE", sid); + console.log("DS_RAG_SETUP_OK project=" + pc + " workflow=" + defCode + " schedule=" + sid); +} + +main().catch(e => { console.error("DS_RAG_SETUP_FAIL", e.message); process.exit(1); }); \ No newline at end of file