Skip to content

Commit

Permalink
retry reading replay a few times
Browse files Browse the repository at this point in the history
  • Loading branch information
poma committed Mar 17, 2016
1 parent b558c4b commit 56a75db
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions StatsFetcher/FileProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,23 @@ public static async Task FetchProfiles(Game game)
public static void ProcessRejoin(string path, Game game)
{
var tmpPath = Path.GetTempFileName();
try {
File.Copy(path, tmpPath, overwrite: true);
}
catch (IOException e) {
File.AppendAllText("log.txt", $"[{DateTime.Now}] Replay copy error: {e}\n\n");

// probably client is still writing this file so we retry a few times
for (int i = 0; i < 5; i++) {
try {
File.Copy(path, tmpPath, overwrite: true);
break;
}
catch (IOException e) {
File.AppendAllText("log.txt", $"[{DateTime.Now}] Replay copy error ({i}): {e}\n\n");
if (i < 4) {
System.Threading.Thread.Sleep(1000); // todo: don't block UI thread
} else {
throw new ApplicationException("Can't access replay file", e);
}
}
}

var replay = ParseRejoin(tmpPath);
foreach (var profile in game.Players) {
var player = replay.Players.Where(p => p.Name == profile.Name).Single();
Expand Down

0 comments on commit 56a75db

Please sign in to comment.