Каркас monorepo: scheduler, data_collector, khbuild_assistant_prep, khb_common; миграции; CI/CD
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
34
packages/data_collector/src/main.ts
Normal file
34
packages/data_collector/src/main.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { createLogger, createPool, loadServiceSettings } from "khb_common";
|
||||
import { jobtreadSchema } from "khb_common";
|
||||
import { collect, jobtreadLoaders } from "./collect.js";
|
||||
import { buildApi } from "./http-api.js";
|
||||
import { importHolidays } from "./holidays/import.js";
|
||||
import { JobtreadSource } from "./jobtread/jobtread-source.js";
|
||||
import { PaveClient } from "./jobtread/pave-client.js";
|
||||
import { runRetention } from "./retention/run.js";
|
||||
import { DEFAULT_RETENTION } from "./retention/policy.js";
|
||||
import { dataCollectorSchema } from "./settings.js";
|
||||
|
||||
const { common, service, raw } = loadServiceSettings("data_collector", dataCollectorSchema);
|
||||
const jt = jobtreadSchema.parse(raw.jobtread);
|
||||
const log = createLogger("data_collector", common.logLevel);
|
||||
const pool = createPool(common.database.url);
|
||||
|
||||
const pave = new PaveClient({ grantKey: jt.grantKey, organizationId: jt.organizationId });
|
||||
const loaders = { jt: jobtreadLoaders(new JobtreadSource(pave)) };
|
||||
const tablesBySource = Object.fromEntries(Object.entries(loaders).map(([k, v]) => [k, v.map((l) => l.table)]));
|
||||
|
||||
const app = buildApi({
|
||||
pool,
|
||||
token: service.http.token,
|
||||
runCollect: async (req, onStarted) => {
|
||||
const results = await collect(pool, loaders, { ...req, sources: req.sources ?? service.sources.map((s: string) => (s === "jobtread" ? "jt" : s)) }, onStarted);
|
||||
for (const r of results) log.info({ snapshotTs: r.snapshotTs, status: r.status, tables: r.tables }, "snapshot finished");
|
||||
return results;
|
||||
},
|
||||
runRetention: () => runRetention(pool, tablesBySource, { ...DEFAULT_RETENTION, ...service.retention }),
|
||||
importHolidays: () => importHolidays(pool, service.holidays),
|
||||
});
|
||||
|
||||
await app.listen({ host: service.http.host, port: service.http.port });
|
||||
log.info({ port: service.http.port }, "data_collector запущен");
|
||||
Reference in New Issue
Block a user