fix: run Codex usage collection in unified service mode

This commit is contained in:
Eyejoker
2026-03-30 02:55:18 +09:00
parent c04b1d9a6f
commit c7725b1cb4

View File

@@ -630,15 +630,11 @@ export async function startUnifiedDashboard(
await updateStatus(); await updateStatus();
if (isRenderer) { if (isRenderer) {
// Renderer: refresh usage cache at shorter interval so Codex snapshot
// data is picked up quickly. Claude API calls are internally rate-limited
// to 5min per token, so this only affects local reads.
setInterval(refreshUsageCache, RENDERER_USAGE_REFRESH_MS); setInterval(refreshUsageCache, RENDERER_USAGE_REFRESH_MS);
} else { }
// Codex service: fetch own usage and expose via status snapshot.
// Active account every usageUpdateInterval; full scan on startup + hourly. // Codex usage collection — runs in unified service regardless of renderer role.
// Collector returns data; we own the cache state. const applyCodexRefresh = (result: {
const applyRefresh = (result: {
rows: UsageRow[]; rows: UsageRow[];
fetchedAt: string | null; fetchedAt: string | null;
}) => { }) => {
@@ -646,18 +642,17 @@ export async function startUnifiedDashboard(
if (result.fetchedAt) codexUsageFetchedAt = result.fetchedAt; if (result.fetchedAt) codexUsageFetchedAt = result.fetchedAt;
}; };
void refreshAllCodexAccountUsage().then((r) => { void refreshAllCodexAccountUsage().then((r) => {
applyRefresh(r); applyCodexRefresh(r);
return refreshActiveCodexUsage().then(applyRefresh); return refreshActiveCodexUsage().then(applyCodexRefresh);
}); });
setInterval( setInterval(
() => void refreshActiveCodexUsage().then(applyRefresh), () => void refreshActiveCodexUsage().then(applyCodexRefresh),
opts.usageUpdateInterval, opts.usageUpdateInterval,
); );
setInterval( setInterval(
() => void refreshAllCodexAccountUsage().then(applyRefresh), () => void refreshAllCodexAccountUsage().then(applyCodexRefresh),
CODEX_FULL_SCAN_INTERVAL, CODEX_FULL_SCAN_INTERVAL,
); );
}
logger.info( logger.info(
{ {