Fix system status update

This commit is contained in:
Christoph Hagen 2023-12-10 19:32:09 +01:00
parent 5e72137d0e
commit 1a1eeb6547
2 changed files with 8 additions and 11 deletions

View File

@ -54,13 +54,10 @@ final class DeviceManager {
self.serverStatus = serverStatus self.serverStatus = serverStatus
} }
func updateMetricsAfterSystemStart() async { func updateDeviceConnectionMetrics() async {
_ = try? await serverStatus.update(deviceIsConnected ? .nominal : .reducedFunctionality) let isConnected = deviceIsConnected
await updateDeviceConnectionMetric() _ = try? await serverStatus.update(isConnected ? .nominal : .reducedFunctionality)
} _ = try? await deviceConnectedMetric.update(isConnected)
private func updateDeviceConnectionMetric() async {
_ = try? await deviceConnectedMetric.update(deviceIsConnected)
} }
private func updateMessageCountMetric() async { private func updateMessageCountMetric() async {
@ -186,7 +183,7 @@ final class DeviceManager {
func removeDeviceConnection() async { func removeDeviceConnection() async {
try? await connection?.close() try? await connection?.close()
connection = nil connection = nil
await updateDeviceConnectionMetric() await updateDeviceConnectionMetrics()
} }
func createNewDeviceConnection(socket: WebSocket, auth: String) async { func createNewDeviceConnection(socket: WebSocket, auth: String) async {
@ -231,6 +228,6 @@ final class DeviceManager {
} }
} }
log("[INFO] Socket connected") log("[INFO] Socket connected")
await updateDeviceConnectionMetric() await updateDeviceConnectionMetrics()
} }
} }

View File

@ -46,7 +46,7 @@ public func configure(_ app: Application) async throws {
monitor.saveCurrentListOfMetricsToLogFolder() monitor.saveCurrentListOfMetricsToLogFolder()
// Update the metric of the device and server status // Update the metric of the device and server status
await deviceManager.updateMetricsAfterSystemStart() await deviceManager.updateDeviceConnectionMetrics()
log("[\(df.string(from: Date()))] Server started") log("[\(df.string(from: Date()))] Server started")
} }