Poll dashboard duplicate cleanup between status updates
Run duplicate dashboard cleanup on a short interval so stale external Status messages are removed between normal status updates.
This commit is contained in:
@@ -4,6 +4,7 @@ import type { UsageRow } from './dashboard-usage-rows.js';
|
||||
import {
|
||||
buildWebUsageRowsForSnapshot,
|
||||
formatStatusHeader,
|
||||
getDashboardDuplicateCleanupIntervalMs,
|
||||
renderUsageTable,
|
||||
shouldPurgeDashboardChannelOnStart,
|
||||
summarizeWatcherTasks,
|
||||
@@ -82,6 +83,13 @@ describe('shouldPurgeDashboardChannelOnStart', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('getDashboardDuplicateCleanupIntervalMs', () => {
|
||||
it('polls duplicate cleanup faster than the status update interval', () => {
|
||||
expect(getDashboardDuplicateCleanupIntervalMs(10_000)).toBe(2_000);
|
||||
expect(getDashboardDuplicateCleanupIntervalMs(1_000)).toBe(1_000);
|
||||
});
|
||||
});
|
||||
|
||||
describe('renderUsageTable', () => {
|
||||
const claudeRow: UsageRow = {
|
||||
name: 'Claude pro',
|
||||
|
||||
@@ -99,6 +99,7 @@ const USAGE_SNAPSHOT_MAX_AGE_MS = 600_000;
|
||||
* so this only affects how quickly Codex snapshot data is picked up.
|
||||
*/
|
||||
const RENDERER_USAGE_REFRESH_MS = 30_000;
|
||||
const DASHBOARD_DUPLICATE_CLEANUP_POLL_MS = 2_000;
|
||||
|
||||
let statusMessageId: string | null = null;
|
||||
let cachedUsageContent = '';
|
||||
@@ -171,6 +172,12 @@ export function shouldPurgeDashboardChannelOnStart(args: {
|
||||
return args.purgeOnStart === true;
|
||||
}
|
||||
|
||||
export function getDashboardDuplicateCleanupIntervalMs(
|
||||
statusUpdateInterval: number,
|
||||
): number {
|
||||
return Math.min(statusUpdateInterval, DASHBOARD_DUPLICATE_CLEANUP_POLL_MS);
|
||||
}
|
||||
|
||||
async function refreshChannelMeta(
|
||||
opts: UnifiedDashboardOptions,
|
||||
): Promise<void> {
|
||||
@@ -798,6 +805,10 @@ export async function startUnifiedDashboard(
|
||||
};
|
||||
|
||||
setInterval(updateStatus, opts.statusUpdateInterval);
|
||||
setInterval(() => {
|
||||
if (!isRenderer || !statusMessageId) return;
|
||||
void cleanupDashboardDuplicateMessages(opts, statusMessageId);
|
||||
}, getDashboardDuplicateCleanupIntervalMs(opts.statusUpdateInterval));
|
||||
await updateStatus();
|
||||
|
||||
if (isRenderer) {
|
||||
|
||||
Reference in New Issue
Block a user