Check bug

This commit is contained in:
Christoph Hagen 2023-09-07 15:30:35 +02:00
parent e52f44f168
commit bc104a9040

View File

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