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,35 +630,30 @@ 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.
// Collector returns data; we own the cache state.
const applyRefresh = (result: {
rows: UsageRow[];
fetchedAt: string | null;
}) => {
cachedCodexUsageRows = result.rows;
if (result.fetchedAt) codexUsageFetchedAt = result.fetchedAt;
};
void refreshAllCodexAccountUsage().then((r) => {
applyRefresh(r);
return refreshActiveCodexUsage().then(applyRefresh);
});
setInterval(
() => void refreshActiveCodexUsage().then(applyRefresh),
opts.usageUpdateInterval,
);
setInterval(
() => void refreshAllCodexAccountUsage().then(applyRefresh),
CODEX_FULL_SCAN_INTERVAL,
);
} }
// Codex usage collection — runs in unified service regardless of renderer role.
const applyCodexRefresh = (result: {
rows: UsageRow[];
fetchedAt: string | null;
}) => {
cachedCodexUsageRows = result.rows;
if (result.fetchedAt) codexUsageFetchedAt = result.fetchedAt;
};
void refreshAllCodexAccountUsage().then((r) => {
applyCodexRefresh(r);
return refreshActiveCodexUsage().then(applyCodexRefresh);
});
setInterval(
() => void refreshActiveCodexUsage().then(applyCodexRefresh),
opts.usageUpdateInterval,
);
setInterval(
() => void refreshAllCodexAccountUsage().then(applyCodexRefresh),
CODEX_FULL_SCAN_INTERVAL,
);
logger.info( logger.info(
{ {
channelId: opts.statusChannelId, channelId: opts.statusChannelId,