in Sources/XCMetricsClient/Mobius/Effect Handlers/CacheLogsEffectHandler.swift [34:67]
func handle(_ effectParameters: (currentLog: URL?, previousLogs: Set<URL>, cachedLogs: Set<URL>, projectName: String),
_ callback: EffectCallback<MetricsUploaderEvent>) -> Disposable {
do {
// Cache other logs that Xcode produced.
var cachedLogsURLs = try logManager.cacheLogs(effectParameters.previousLogs, cachedLogs: effectParameters.cachedLogs, retries: 0)
// Cache currentLog separately, to keep track of its cached location.
var cachedCurrentLogURLs: Set<URL> = []
if let currentLog = effectParameters.currentLog {
cachedCurrentLogURLs = try logManager.cacheLogs(Set([currentLog]),
cachedLogs: cachedLogsURLs.union(effectParameters.cachedLogs),
retries: logCopyRetries)
cachedLogsURLs = cachedLogsURLs.union(cachedCurrentLogURLs)
}
log("Successfully cached logs: \(cachedLogsURLs)")
// Retrieve requests that previously failed to upload.
let requestsToRetry = try logManager.retrieveLogRequestsToUpload()
// Transforms the contents of the cached logs into an actual MetricsUploadRequest.
let cachedUploadRequests: Set<MetricsUploadRequest> = Set(requestsToRetry.map {
MetricsUploadRequest(fileURL: $0)
})
log("Successfully fetched requests that failed to upload previously: \(requestsToRetry))")
callback.end(
with: .logsCached(
currentLog: cachedCurrentLogURLs.first,
previousLogs: cachedLogsURLs.subtracting(cachedCurrentLogURLs),
cachedUploadRequests: cachedUploadRequests
)
)
} catch {
exit(1, error.localizedDescription)
}
return AnonymousDisposable {}
}