Fix false stale Fleet reports caused by clock skew
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { derived, get, writable } from 'svelte/store';
|
||||
import { browser } from '$app/environment';
|
||||
import { statusByServer, statusReceivedAt } from './servers.js';
|
||||
import { statusByServer, statusReceivedAt, serverTimeNow, syncServerTime } from './servers.js';
|
||||
import { watchSatisfied, type FleetServer, type FleetOperation, type LobbyWatch } from '$lib/fleet-overview.js';
|
||||
import { serverTitle } from '../server-labels.js';
|
||||
import { toast } from '../toast.js';
|
||||
@@ -39,6 +39,7 @@ export function refreshFleet(): Promise<void> {
|
||||
]);
|
||||
if (responses.some(response => !response.ok)) throw new Error('Could not refresh Fleet. Retrying automatically.');
|
||||
const [servers, operations] = await Promise.all(responses.map(response => response.json()));
|
||||
syncServerTime(servers.serverNow);
|
||||
fleetError.set('');
|
||||
fleetIntegrations.set(servers.integrations);
|
||||
fleet.set({ servers: servers.servers, operations: operations.operations, receivedAt: requestedAt });
|
||||
@@ -93,7 +94,7 @@ export function startFleetMonitor(): () => void {
|
||||
if (!snapshot.receivedAt || Date.now() - snapshot.receivedAt > 30_000) return;
|
||||
const servers = get(fleetServers);
|
||||
for (const watch of get(lobbyWatches)) {
|
||||
if (!watchSatisfied(watch, servers.find(server => server.name === watch.server), snapshot.operations, Date.now())) continue;
|
||||
if (!watchSatisfied(watch, servers.find(server => server.name === watch.server), snapshot.operations, serverTimeNow())) continue;
|
||||
const message = `${serverTitle(watch.server)} ${watch.kind === 'empty' ? 'is empty' : watch.kind === 'online' ? 'is back online' : 'has finished its operation'}.`;
|
||||
cancelWatch(watch.id);
|
||||
toast(message, { variant: 'success', ttl: 0, href: watch.href });
|
||||
|
||||
Reference in New Issue
Block a user