Some checks failed
Publish Swift Package / build-test-publish (push) Failing after 20s
Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
71 lines
2.2 KiB
Swift
71 lines
2.2 KiB
Swift
import Foundation
|
|
|
|
/// Statistics for sync operations
|
|
public struct SyncStats: Sendable, Codable, Equatable {
|
|
/// Total number of successful sync operations
|
|
public var successCount: Int
|
|
|
|
/// Total number of failed sync operations
|
|
public var failureCount: Int
|
|
|
|
/// Total number of items synced across all operations
|
|
public var itemsSynced: Int
|
|
|
|
/// Total bytes transferred across all operations
|
|
public var bytesTransferred: Int64
|
|
|
|
/// Timestamp of the last successful sync
|
|
public var lastSuccessAt: Date?
|
|
|
|
/// Timestamp of the last failed sync
|
|
public var lastFailureAt: Date?
|
|
|
|
/// Duration of the most recent sync operation in seconds
|
|
public var lastDurationSeconds: TimeInterval?
|
|
|
|
/// Average duration of sync operations in seconds
|
|
public var averageDurationSeconds: TimeInterval? {
|
|
let total = successCount + failureCount
|
|
guard total > 0, let lastDuration = lastDurationSeconds else { return nil }
|
|
return lastDuration // Simplified; a real implementation would track cumulative
|
|
}
|
|
|
|
public init(
|
|
successCount: Int = 0,
|
|
failureCount: Int = 0,
|
|
itemsSynced: Int = 0,
|
|
bytesTransferred: Int64 = 0,
|
|
lastSuccessAt: Date? = nil,
|
|
lastFailureAt: Date? = nil,
|
|
lastDurationSeconds: TimeInterval? = nil
|
|
) {
|
|
self.successCount = successCount
|
|
self.failureCount = failureCount
|
|
self.itemsSynced = itemsSynced
|
|
self.bytesTransferred = bytesTransferred
|
|
self.lastSuccessAt = lastSuccessAt
|
|
self.lastFailureAt = lastFailureAt
|
|
self.lastDurationSeconds = lastDurationSeconds
|
|
}
|
|
|
|
/// Record a successful sync
|
|
public mutating func recordSuccess(items: Int, bytes: Int64, duration: TimeInterval) {
|
|
successCount += 1
|
|
itemsSynced += items
|
|
bytesTransferred += bytes
|
|
lastSuccessAt = Date()
|
|
lastDurationSeconds = duration
|
|
}
|
|
|
|
/// Record a failed sync
|
|
public mutating func recordFailure(duration: TimeInterval) {
|
|
failureCount += 1
|
|
lastFailureAt = Date()
|
|
lastDurationSeconds = duration
|
|
}
|
|
|
|
/// Reset all statistics
|
|
public mutating func reset() {
|
|
self = SyncStats()
|
|
}
|
|
}
|