mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-14 02:42:24 +03:00
Feature grande e bem construída: exportação contínua de call logs para destinos plugáveis (BigQuery primeiro). Revisei especificamente o tratamento de segredos (`src/lib/logExport/secrets.ts`) e a migração — encryption gate real (`requiresEncryptionKey` recusa gravação em texto plano quando `STORAGE_ENCRYPTION_KEY` não está setada), redação antes de qualquer resposta de API, e a migração cria a tabela com `enabled=0`/`include_bodies=0` por padrão (opt-in, sem exportar nada até o operador configurar). 62/62 testes focados verdes, typecheck limpo. Resolvido o conflito com o barrel `src/lib/localDb.ts` (removido nesta mesma sessão, #11795 fase 5 — todo consumidor já migrado para `src/lib/db/*`); a PR só adicionava um re-export nele, que não é mais necessário. Obrigado pela contribuição!
59 lines
2.1 KiB
TypeScript
59 lines
2.1 KiB
TypeScript
import initializeCloudSync from "@/shared/services/initializeCloudSync";
|
|
import { startModelSyncScheduler } from "@/shared/services/modelSyncScheduler";
|
|
import { isAutomatedTestProcess } from "@/shared/utils/testProcess";
|
|
import { getJobRegistry } from "@/lib/jobRegistry";
|
|
import { registerBudgetResetJob } from "@/lib/jobs/budgetResetJob";
|
|
import { registerTokenHealthCheck } from "@/lib/jobs/tokenHealthCheckJob";
|
|
import { registerLogExportJob } from "@/lib/jobs/logExportJob";
|
|
import { backfillVolcPlanAutoSync } from "@/lib/providers/volcPlanAutoSyncBackfill";
|
|
|
|
// Initialize runtime background sync services once per server process.
|
|
let initialized = false;
|
|
|
|
export function shouldSkipCloudSyncInitialization(
|
|
env: NodeJS.ProcessEnv = process.env,
|
|
argv: string[] = process.argv
|
|
): boolean {
|
|
if (env.NEXT_PHASE === "phase-production-build") {
|
|
return true;
|
|
}
|
|
|
|
const raw = env.OMNIROUTE_DISABLE_BACKGROUND_SERVICES;
|
|
if (raw && new Set(["1", "true", "yes", "on"]).has(raw.trim().toLowerCase())) {
|
|
return true;
|
|
}
|
|
|
|
return isAutomatedTestProcess(argv, env) && env.OMNIROUTE_ENABLE_RUNTIME_BACKGROUND_TASKS !== "1";
|
|
}
|
|
|
|
export async function ensureCloudSyncInitialized() {
|
|
if (shouldSkipCloudSyncInitialization()) {
|
|
return false;
|
|
}
|
|
if (!initialized) {
|
|
try {
|
|
await initializeCloudSync();
|
|
await backfillVolcPlanAutoSync();
|
|
startModelSyncScheduler();
|
|
|
|
// startAll() runs each interval job's first tick synchronously, so it has to
|
|
// come after initializeCloudSync(). The old wiring got that ordering two
|
|
// different ways: the budget reset was started right here, and the health
|
|
// check's first sweep sat behind a 10s timer. Awaiting the init is a firmer
|
|
// guarantee than the timer was.
|
|
const registry = getJobRegistry();
|
|
registerBudgetResetJob(registry);
|
|
registerTokenHealthCheck(registry);
|
|
registerLogExportJob(registry);
|
|
await registry.startAll();
|
|
|
|
initialized = true;
|
|
} catch (error) {
|
|
console.error("[ServerInit] Error initializing background sync services:", error);
|
|
}
|
|
}
|
|
return initialized;
|
|
}
|
|
|
|
export default ensureCloudSyncInitialized;
|