Improve logging and shutdown
This commit is contained in:
parent
2e11023096
commit
c25c4f3dc6
@ -51,17 +51,15 @@ public func configure(_ app: Application) async throws {
|
||||
log("[\(df.string(from: Date()))] Server started")
|
||||
}
|
||||
|
||||
public func shutdown() {
|
||||
print("[\(df.string(from: Date()))] Server shutdown")
|
||||
asyncScheduler.schedule {
|
||||
// Gracefully shut down by closing potentially open socket
|
||||
await deviceManager.removeDeviceConnection()
|
||||
do {
|
||||
try await asyncScheduler.shutdownGracefully()
|
||||
} catch {
|
||||
print("Failed to shut down MultiThreadedEventLoopGroup: \(error)")
|
||||
}
|
||||
public func shutdown() async {
|
||||
// Gracefully shut down by closing potentially open socket
|
||||
await deviceManager.removeDeviceConnection()
|
||||
do {
|
||||
try await asyncScheduler.shutdownGracefully()
|
||||
} catch {
|
||||
print("Failed to shut down MultiThreadedEventLoopGroup: \(error)")
|
||||
}
|
||||
print("[\(df.string(from: Date()))] Server shutdown")
|
||||
}
|
||||
|
||||
private func loadKeys(at url: URL) throws -> (deviceKey: Data, remoteKey: Data) {
|
||||
|
@ -23,21 +23,29 @@ private extension Vapor.Application {
|
||||
@main
|
||||
enum Entrypoint {
|
||||
static func main() async throws {
|
||||
var env = try Environment.detect()
|
||||
var env = Environment.production
|
||||
try LoggingSystem.bootstrap(from: &env)
|
||||
|
||||
let app = Application(env)
|
||||
defer {
|
||||
shutdown()
|
||||
func cleanup() async {
|
||||
await shutdown()
|
||||
app.shutdown()
|
||||
}
|
||||
|
||||
do {
|
||||
try await configure(app)
|
||||
await cleanup()
|
||||
} catch {
|
||||
app.logger.report(error: error)
|
||||
await cleanup()
|
||||
throw error
|
||||
}
|
||||
do {
|
||||
try await app.runFromAsyncMainEntrypoint()
|
||||
await cleanup()
|
||||
} catch {
|
||||
await cleanup()
|
||||
throw error
|
||||
}
|
||||
try await app.runFromAsyncMainEntrypoint()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user