mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-25 08:32:11 +03:00
⭐5 — Health-check failures compartilhavam o mesmo caminho de escrita de terminalStatus que requests reais, banindo conexão por health-check falho (403) por um ano. Novo helper origin-aware centraliza toda escrita terminal; health-check só loga, request real desativa como antes. TDD, 6/6 testes, lint/typecheck/cycles OK.
30 lines
1.4 KiB
TypeScript
30 lines
1.4 KiB
TypeScript
import { updateProviderConnection } from "@/lib/db/providers";
|
|
import { shouldIsolateProbeFailures } from "@/shared/utils/probeOrigin";
|
|
|
|
type Patch = { testStatus: string; isActive?: boolean; lastError?: string | null; errorCode?: string | null; lastErrorType?: string | null; lastErrorAt?: string | null };
|
|
const TERMINAL = new Set(["banned","expired","deactivated","credits_exhausted"]);
|
|
|
|
export async function writeTerminalStatus(connectionId: string, patch: Patch, origin: "probe" | "production"): Promise<void> {
|
|
const isTerminal = TERMINAL.has(patch.testStatus.toLowerCase());
|
|
// Double gate: AsyncLocalStorage probe + explicit origin "probe" — fail-safe ON
|
|
const probeIsolated = await shouldIsolateProbeFailures();
|
|
if ((origin === "probe" || probeIsolated) && isTerminal) {
|
|
// record-only: never remove from pool
|
|
await updateProviderConnection(connectionId, {
|
|
lastError: patch.lastError ?? null,
|
|
lastErrorAt: new Date().toISOString(),
|
|
lastErrorType: patch.lastErrorType ?? null,
|
|
errorCode: patch.errorCode ?? null,
|
|
});
|
|
return;
|
|
}
|
|
await updateProviderConnection(connectionId, {
|
|
isActive: patch.isActive ?? (isTerminal ? false : undefined),
|
|
testStatus: patch.testStatus,
|
|
lastError: patch.lastError ?? null,
|
|
lastErrorAt: new Date().toISOString(),
|
|
lastErrorType: patch.lastErrorType ?? null,
|
|
errorCode: patch.errorCode ?? null,
|
|
});
|
|
}
|