diff --git a/Sources/App/DeviceManager.swift b/Sources/App/DeviceManager.swift index 278b5b9..2928a7b 100644 --- a/Sources/App/DeviceManager.swift +++ b/Sources/App/DeviceManager.swift @@ -53,14 +53,11 @@ final class DeviceManager { description: "The number of messages transmitted to the device") self.serverStatus = serverStatus } - - func updateMetricsAfterSystemStart() async { - _ = try? await serverStatus.update(deviceIsConnected ? .nominal : .reducedFunctionality) - await updateDeviceConnectionMetric() - } - - private func updateDeviceConnectionMetric() async { - _ = try? await deviceConnectedMetric.update(deviceIsConnected) + + func updateDeviceConnectionMetrics() async { + let isConnected = deviceIsConnected + _ = try? await serverStatus.update(isConnected ? .nominal : .reducedFunctionality) + _ = try? await deviceConnectedMetric.update(isConnected) } private func updateMessageCountMetric() async { @@ -186,7 +183,7 @@ final class DeviceManager { func removeDeviceConnection() async { try? await connection?.close() connection = nil - await updateDeviceConnectionMetric() + await updateDeviceConnectionMetrics() } func createNewDeviceConnection(socket: WebSocket, auth: String) async { @@ -231,6 +228,6 @@ final class DeviceManager { } } log("[INFO] Socket connected") - await updateDeviceConnectionMetric() + await updateDeviceConnectionMetrics() } } diff --git a/Sources/App/configure.swift b/Sources/App/configure.swift index 4bab95b..2dae169 100755 --- a/Sources/App/configure.swift +++ b/Sources/App/configure.swift @@ -46,7 +46,7 @@ public func configure(_ app: Application) async throws { monitor.saveCurrentListOfMetricsToLogFolder() // Update the metric of the device and server status - await deviceManager.updateMetricsAfterSystemStart() + await deviceManager.updateDeviceConnectionMetrics() log("[\(df.string(from: Date()))] Server started") }