diff --git a/Sources/App/configure.swift b/Sources/App/configure.swift index 353a048..d942de2 100755 --- a/Sources/App/configure.swift +++ b/Sources/App/configure.swift @@ -23,7 +23,7 @@ private let dateFormatter: DateFormatter = { public func configure(_ app: Application) async throws { let storageFolder = URL(fileURLWithPath: app.directory.resourcesDirectory) let logFolder = storageFolder.appendingPathComponent("logs") - try await migrate(folder: logFolder) + try migrate(folder: logFolder) fatalError("Done") let monitor = MetricObserver(logFileFolder: logFolder, logMetricId: "sesame.log") @@ -91,14 +91,14 @@ func log(_ message: String) { import CBORCoding -private func migrate(folder: URL) async throws { - try await migrateMetric("sesame.log", containing: String.self, in: folder) - try await migrateMetric("sesame.status", containing: ServerStatus.self, in: folder) - try await migrateMetric("sesame.connected", containing: Bool.self, in: folder) - try await migrateMetric("sesame.messages", containing: Int.self, in: folder) +private func migrate(folder: URL) throws { + try migrateMetric("sesame.log", containing: String.self, in: folder) + try migrateMetric("sesame.status", containing: ServerStatus.self, in: folder) + try migrateMetric("sesame.connected", containing: Bool.self, in: folder) + try migrateMetric("sesame.messages", containing: Int.self, in: folder) } -private func migrateMetric(_ id: String, containing type: T.Type, in folder: URL) async throws where T: MetricValue { +private func migrateMetric(_ id: String, containing type: T.Type, in folder: URL) throws where T: MetricValue { print("Processing metric \(id)") let file = id.hashed() let url = folder.appendingPathComponent(file) @@ -120,8 +120,10 @@ private func migrateMetric(_ id: String, containing type: T.Type, in folder: // TODO: Write values back to disk let observer = MetricObserver(logFileFolder: folder, logMetricId: "sesame.migration") let metric: Metric = observer.addMetric(id: id) - try await metric.update(all) - + Task { + try await metric.update(all) + print("Saved all values for metric \(id)") + } print("Finished metric \(id)") } @@ -162,7 +164,7 @@ private func readElements(from url: URL) throws -> [Timestamped] where T: let element: T = try decoder.decode(from: elementData) result.append(.init(value: element, timestamp: date)) currentIndex = nextIndex - if result.count % 100 == 0 { + if result.count % 100 == 1 { print("File \(file): \(result.count) entries loaded (\(currentIndex)/\(data.endIndex) bytes)") } }