Test logger
This commit is contained in:
parent
4489092a6f
commit
b9f1827b63
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user