diff --git a/APSIM.POStats.Collector/Program.cs b/APSIM.POStats.Collector/Program.cs
index 016cdf7..5584272 100644
--- a/APSIM.POStats.Collector/Program.cs
+++ b/APSIM.POStats.Collector/Program.cs
@@ -5,6 +5,7 @@
using System.Diagnostics;
using System.Globalization;
using System.IO;
+using System.Threading;
using System.Threading.Tasks;
namespace APSIM.POStats.Collector
@@ -147,7 +148,7 @@ private static void UploadStats(PullRequest pullRequest, string url)
}
}
}
-
+
///
/// Upload method for Jenkins
///
@@ -179,19 +180,10 @@ private static void UploadStatsJenkins(PullRequestJenkins pullRequest)
pullRequest.Files.Clear();
pullRequest.Files.Add(file);
- Console.WriteLine($"Sending POStats data to web api for file {file.Name}");
+ bool success = UploadStatsJenkinsSend(url, pullRequest, file.Name);
- try
- {
- response = WebUtilities.PostAsync($"{url}/adddata", pullRequest, null);
- response.Wait();
- }
- catch (Exception exception)
- {
- Console.WriteLine($"Error when collecting file {file.Name}");
- Console.WriteLine(exception.Message);
+ if (!success)
ok = false;
- }
}
// Tell endpoint we're about to upload data.
@@ -205,5 +197,39 @@ private static void UploadStatsJenkins(PullRequestJenkins pullRequest)
throw new Exception("Errors Uploading data to POStats");
}
}
+
+ ///
+ /// Upload method for Jenkins
+ ///
+ ///
+ ///
+ ///
+ ///
+ private static bool UploadStatsJenkinsSend(string url, PullRequestJenkins pullRequest, string filename)
+ {
+ int attempts = 0;
+ while (attempts < 4)
+ {
+ attempts += 1;
+ Console.WriteLine($"Sending POStats data to web api for file {filename}. Attempt {attempts}");
+ try
+ {
+ Task response = WebUtilities.PostAsync($"{url}/adddata", pullRequest, null);
+ response.Wait();
+ return true;
+ }
+ catch (Exception exception)
+ {
+ Thread.Sleep(1000);
+ if (attempts == 4)
+ {
+ Console.WriteLine($"Error when collecting file {filename}");
+ Console.WriteLine(exception.Message);
+ return false;
+ }
+ }
+ }
+ return true;
+ }
}
}
\ No newline at end of file