Test logger

This commit is contained in:
Christoph Hagen 2023-12-08 20:26:17 +01:00
parent 4489092a6f
commit b9f1827b63
2 changed files with 13 additions and 2 deletions

View File

@ -33,6 +33,12 @@ final class DeviceManager {
private var requestInProgress: CheckedContinuation<Data, Error>?
private var receivedMessageData: Data?
var logger: Logger?
private func printAndFlush(_ message: String) {
logger?.notice(.init(stringLiteral: message))
}
init(deviceKey: Data, remoteKey: Data, deviceTimeout: Int64, serverStatus: Metric<ServerStatus>) {
self.deviceKey = deviceKey
self.remoteKey = remoteKey
@ -89,6 +95,7 @@ final class DeviceManager {
// Check if a full message has already been received
if let receivedMessageData, receivedMessageData.count == SignedMessage.size {
printAndFlush("[INFO] Full message from socket collected early")
self.receivedMessageData = nil
return receivedMessageData
}
@ -97,12 +104,16 @@ final class DeviceManager {
self.requestInProgress = continuation
}
await updateMessageCountMetric()
printAndFlush("[INFO] Message completed")
return result
}
private func startTimeoutForDeviceRequest(on eventLoop: EventLoop) {
eventLoop.scheduleTask(in: .seconds(deviceTimeout)) { [weak self] in
self?.resumeDeviceRequest(with: .deviceTimedOut)
guard let self else {
printAndFlush("[INFO] Message completed")
}
self.resumeDeviceRequest(with: .deviceTimedOut)
}
}

View File

@ -37,7 +37,7 @@ public func configure(_ app: Application) async throws {
let (deviceKey, remoteKey) = try loadKeys(at: keyFile)
deviceManager = DeviceManager(deviceKey: deviceKey, remoteKey: remoteKey, deviceTimeout: config.deviceTimeout, serverStatus: status)
deviceManager.logger = app.logger
routes(app)
provider = .init(observer: monitor, accessManager: config.authenticationTokens)