Rework shutdown procedure

This commit is contained in:
Christoph Hagen 2023-11-28 11:20:29 +01:00
parent ab2a14e00b
commit f60cb3c05a

View File

@ -58,21 +58,15 @@ public func configure(_ app: Application) throws {
}
log("[\(df.string(from: Date()))] Server started")
// Gracefully shut down by closing potentially open socket
// Must be done after app is running, otherwise error is thrown
DispatchQueue.global(qos: .utility).asyncAfter(deadline: .now() + .seconds(5)) {
_ = app.server.onShutdown.always { _ in
print("[\(df.string(from: Date()))] Server shutdown")
asyncScheduler.schedule {
await deviceManager.removeDeviceConnection()
}
}
}
}
public func shutdown() {
try? asyncScheduler.syncShutdownGracefully()
print("[\(df.string(from: Date()))] Server shutdown")
asyncScheduler.schedule {
// Gracefully shut down by closing potentially open socket
await deviceManager.removeDeviceConnection()
try? await asyncScheduler.shutdownGracefully()
}
}
private func loadKeys(at url: URL) throws -> (deviceKey: Data, remoteKey: Data) {