|
|
|
|
@ -80,17 +80,39 @@ class SourceFileManager { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
actor SourceFileDownloadTracker { |
|
|
|
|
var _downloadedFileStatus : Int? = nil |
|
|
|
|
|
|
|
|
|
func updateIfNecessary(with successState: Int?) { |
|
|
|
|
if successState != nil && (_downloadedFileStatus == nil || _downloadedFileStatus == 0) { |
|
|
|
|
_downloadedFileStatus = successState |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func getDownloadedFileStatus() -> Int? { |
|
|
|
|
return _downloadedFileStatus |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//return nil if no new files |
|
|
|
|
//return 1 if new file to import |
|
|
|
|
//return 0 if new file just to re-calc static data, no need to re-import |
|
|
|
|
@discardableResult |
|
|
|
|
func fetchData(fromDate current: Date) async -> Bool { |
|
|
|
|
func fetchData(fromDate current: Date) async -> Int? { |
|
|
|
|
let lastStringDate = URL.importDateFormatter.string(from: current) |
|
|
|
|
|
|
|
|
|
let files = ["MESSIEURS", "MESSIEURS-2", "MESSIEURS-3", "MESSIEURS-4", "DAMES"] |
|
|
|
|
|
|
|
|
|
let sourceFileDownloadTracker = SourceFileDownloadTracker() |
|
|
|
|
|
|
|
|
|
do { |
|
|
|
|
try await withThrowingTaskGroup(of: Void.self) { group in // Mark 1 |
|
|
|
|
|
|
|
|
|
for file in files { |
|
|
|
|
group.addTask { |
|
|
|
|
try await NetworkManager.shared.downloadRankingData(lastDateString: lastStringDate, fileName: file) |
|
|
|
|
group.addTask { [sourceFileDownloadTracker] in |
|
|
|
|
let success = try await NetworkManager.shared.downloadRankingData(lastDateString: lastStringDate, fileName: file) |
|
|
|
|
await sourceFileDownloadTracker.updateIfNecessary(with: success) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -102,7 +124,6 @@ class SourceFileManager { |
|
|
|
|
// await fetchData(fromDate: nextCurrent) |
|
|
|
|
// } |
|
|
|
|
// } |
|
|
|
|
return true |
|
|
|
|
} catch { |
|
|
|
|
print("downloadRankingData", error) |
|
|
|
|
|
|
|
|
|
@ -111,10 +132,10 @@ class SourceFileManager { |
|
|
|
|
await fetchData(fromDate: previousDate) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return false |
|
|
|
|
} |
|
|
|
|
let downloadedFileStatus = await sourceFileDownloadTracker.getDownloadedFileStatus() |
|
|
|
|
|
|
|
|
|
return downloadedFileStatus |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func getAllFiles(initialDate: String = "08-2022") async { |
|
|
|
|
|