Preserve verified health when provisioning completes
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
import type { RconStatusResult } from '../integrations/rcon.js';
|
||||
import type { ServerObservation } from '../../server-observation.js';
|
||||
import type { ServerRow } from './servers.js';
|
||||
|
||||
/** Monitoring and provisioning publish the same complete RCON observation. */
|
||||
export function successfulStatusFields(result: Extract<RconStatusResult, { ok: true }>, observedAt: string): Partial<ServerRow> {
|
||||
return {
|
||||
last_checked_at: observedAt, last_seen_at: observedAt,
|
||||
last_players: result.status.players, last_map: result.status.map,
|
||||
last_gametype: result.status.gametype, last_roster: JSON.stringify(result.status.roster),
|
||||
last_reply_snippet: result.rawReply ?? null, last_error: null, rcon_failures: 0
|
||||
};
|
||||
}
|
||||
|
||||
/** Occupancy timers and match clearing follow the same source as the UI. */
|
||||
export function activityFields(current: ServerRow, status: ServerObservation): Partial<ServerRow> {
|
||||
if (status.health !== 'online' || status.last_players === null) return {};
|
||||
return status.last_players > 0
|
||||
? { active_since: current.active_since ?? status.last_seen_at, inactive_since: null }
|
||||
: { active_since: null, inactive_since: current.inactive_since ?? status.last_seen_at,
|
||||
game_started_at: null, game_ended_at: null };
|
||||
}
|
||||
Reference in New Issue
Block a user