Skip to content

Commit

Permalink
Merge pull request #139 from kartverket/retryDownloadIfFails
Browse files Browse the repository at this point in the history
retry downloads if failing
  • Loading branch information
jarped committed Sep 21, 2020
2 parents f3836bd + 59cf75e commit 5c24099
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,30 @@ public DownloadController(string changelogFilename)
public bool DownloadChangelog(string downloadUri, Dataset dataset)
{
var webClient = new WebClient { Credentials = new NetworkCredential(dataset.UserName, dataset.Password) };
webClient.DownloadFile(downloadUri, ChangelogFilename);

var tries = 0;

var waitMilliseconds = 300;

while (tries < 10)
{
try
{
webClient.DownloadFile(downloadUri, ChangelogFilename);
break;
}
catch (Exception e)
{
System.Threading.Thread.Sleep(waitMilliseconds);

waitMilliseconds *= 2;

tries += 1;

if (tries == 9) throw;
}
}

if (File.Exists(ChangelogFilename))
{
UnpackZipFile(ChangelogFilename);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public bool GetChangelog(int datasetId, string changelogId, out DownloadControll
#endif

downloadController = new DownloadController {ChangelogFilename = fileName};
downloadController.DownloadChangelog(downloaduri, dataset);
downloadController.DownloadChangelog(downloaduri, dataset);
}
catch (WebException webEx)
{
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

[Downloads](https://github.com/kartverket/geosynkronisering/releases)

[Documentation for alternative subscriber for non-windows](https://github.com/kartverket/geosynkronisering/tree/fixDotnetstandard/Kartverket.Geosynkronisering.Subscriber/Test_Subscriber_NetCore)
[Documentation for alternative subscriber for non-windows](https://github.com/kartverket/geosynkronisering/tree/master/Kartverket.Geosynkronisering.Subscriber/Test_Subscriber_NetCore)

[Deprecated version](https://github.com/kartverket/CORESubscriber)

Expand Down

0 comments on commit 5c24099

Please sign in to comment.