Каркас monorepo: scheduler, data_collector, khbuild_assistant_prep, khb_common; миграции; CI/CD
Some checks failed
ci / test (push) Failing after 20s
ci / deploy (push) Has been skipped

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-11 09:44:50 +03:00
commit ebb1cb7950
101 changed files with 4971 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
import type { DispatchResult } from "./tick.js";
import type { JobSettings, SchedulerSettings } from "./settings.js";
/** HTTP-вызов сервиса по описанию задания (Bearer-токен сервиса из settings.scheduler.services). */
export function makeHttpDispatch(services: SchedulerSettings["services"], fetchFn: typeof fetch = fetch) {
return async (job: JobSettings): Promise<DispatchResult> => {
const svc = services[job.call.service];
if (!svc) return { httpStatus: 0, message: `неизвестный сервис ${job.call.service}` };
const res = await fetchFn(svc.baseUrl + job.call.path, {
method: job.call.method,
headers: { authorization: `Bearer ${svc.token}`, "content-type": "application/json" },
body: job.call.method === "POST" ? JSON.stringify(job.call.body ?? {}) : undefined,
signal: AbortSignal.timeout(30_000),
});
const text = await res.text();
let ref: string | undefined;
try {
const j = JSON.parse(text) as { snapshotTs?: string; runId?: string };
ref = j.snapshotTs ?? j.runId;
} catch {
/* ответ не JSON */
}
return { httpStatus: res.status, responseRef: ref, message: res.ok ? undefined : text.slice(0, 300) };
};
}