Skip to content

Commit

Permalink
Added Polly
Browse files Browse the repository at this point in the history
  • Loading branch information
andersosthus committed Jan 30, 2017
1 parent 039fca2 commit 1d87df7
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 8 deletions.
7 changes: 4 additions & 3 deletions src/ServiceFabricUploader/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ static int Main(string[] args)
var errCode = app.Execute(args);
if (errCode != 0)
{
Console.WriteLine("Error parsing options...");
Console.WriteLine();
//Console.WriteLine("Error parsing options...");
//Console.WriteLine();

app.ShowHelp();
//app.ShowHelp();
Console.WriteLine($"Something went wrong - exited with status code {errCode}");
return errCode;
}
}
Expand Down
93 changes: 93 additions & 0 deletions src/ServiceFabricUploader/project.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,18 @@
"lib/netstandard1.0/Newtonsoft.Json.dll": {}
}
},
"Polly/5.0.3": {
"type": "package",
"dependencies": {
"NETStandard.Library": "1.6.0"
},
"compile": {
"lib/netstandard1.0/Polly.dll": {}
},
"runtime": {
"lib/netstandard1.0/Polly.dll": {}
}
},
"runtime.debian.8-x64.runtime.native.System.Security.Cryptography.OpenSsl/4.3.0": {
"type": "package",
"runtimeTargets": {
Expand Down Expand Up @@ -2362,6 +2374,7 @@
"Microsoft.AspNetCore.WebUtilities": "1.0.0",
"NETStandard.Library": "1.6.0",
"Newtonsoft.Json": "9.0.1",
"Polly": "5.0.3",
"System.Net.Http": "4.1.0"
},
"compile": {
Expand Down Expand Up @@ -2775,6 +2788,18 @@
"lib/netstandard1.0/Newtonsoft.Json.dll": {}
}
},
"Polly/5.0.3": {
"type": "package",
"dependencies": {
"NETStandard.Library": "1.6.0"
},
"compile": {
"lib/netstandard1.0/Polly.dll": {}
},
"runtime": {
"lib/netstandard1.0/Polly.dll": {}
}
},
"runtime.any.System.Collections/4.3.0": {
"type": "package",
"dependencies": {
Expand Down Expand Up @@ -4914,6 +4939,7 @@
"Microsoft.AspNetCore.WebUtilities": "1.0.0",
"NETStandard.Library": "1.6.0",
"Newtonsoft.Json": "9.0.1",
"Polly": "5.0.3",
"System.Net.Http": "4.1.0"
},
"compile": {
Expand Down Expand Up @@ -5327,6 +5353,18 @@
"lib/netstandard1.0/Newtonsoft.Json.dll": {}
}
},
"Polly/5.0.3": {
"type": "package",
"dependencies": {
"NETStandard.Library": "1.6.0"
},
"compile": {
"lib/netstandard1.0/Polly.dll": {}
},
"runtime": {
"lib/netstandard1.0/Polly.dll": {}
}
},
"runtime.any.System.Collections/4.3.0": {
"type": "package",
"dependencies": {
Expand Down Expand Up @@ -7427,6 +7465,7 @@
"Microsoft.AspNetCore.WebUtilities": "1.0.0",
"NETStandard.Library": "1.6.0",
"Newtonsoft.Json": "9.0.1",
"Polly": "5.0.3",
"System.Net.Http": "4.1.0"
},
"compile": {
Expand Down Expand Up @@ -7843,6 +7882,18 @@
"lib/netstandard1.0/Newtonsoft.Json.dll": {}
}
},
"Polly/5.0.3": {
"type": "package",
"dependencies": {
"NETStandard.Library": "1.6.0"
},
"compile": {
"lib/netstandard1.0/Polly.dll": {}
},
"runtime": {
"lib/netstandard1.0/Polly.dll": {}
}
},
"runtime.any.System.Collections/4.3.0": {
"type": "package",
"dependencies": {
Expand Down Expand Up @@ -10071,6 +10122,7 @@
"Microsoft.AspNetCore.WebUtilities": "1.0.0",
"NETStandard.Library": "1.6.0",
"Newtonsoft.Json": "9.0.1",
"Polly": "5.0.3",
"System.Net.Http": "4.1.0"
},
"compile": {
Expand Down Expand Up @@ -10487,6 +10539,18 @@
"lib/netstandard1.0/Newtonsoft.Json.dll": {}
}
},
"Polly/5.0.3": {
"type": "package",
"dependencies": {
"NETStandard.Library": "1.6.0"
},
"compile": {
"lib/netstandard1.0/Polly.dll": {}
},
"runtime": {
"lib/netstandard1.0/Polly.dll": {}
}
},
"runtime.any.System.Collections/4.3.0": {
"type": "package",
"dependencies": {
Expand Down Expand Up @@ -12619,6 +12683,7 @@
"Microsoft.AspNetCore.WebUtilities": "1.0.0",
"NETStandard.Library": "1.6.0",
"Newtonsoft.Json": "9.0.1",
"Polly": "5.0.3",
"System.Net.Http": "4.1.0"
},
"compile": {
Expand Down Expand Up @@ -13035,6 +13100,18 @@
"lib/netstandard1.0/Newtonsoft.Json.dll": {}
}
},
"Polly/5.0.3": {
"type": "package",
"dependencies": {
"NETStandard.Library": "1.6.0"
},
"compile": {
"lib/netstandard1.0/Polly.dll": {}
},
"runtime": {
"lib/netstandard1.0/Polly.dll": {}
}
},
"runtime.any.System.Collections/4.3.0": {
"type": "package",
"dependencies": {
Expand Down Expand Up @@ -15149,6 +15226,7 @@
"Microsoft.AspNetCore.WebUtilities": "1.0.0",
"NETStandard.Library": "1.6.0",
"Newtonsoft.Json": "9.0.1",
"Polly": "5.0.3",
"System.Net.Http": "4.1.0"
},
"compile": {
Expand Down Expand Up @@ -15589,6 +15667,21 @@
"tools/install.ps1"
]
},
"Polly/5.0.3": {
"sha512": "Kg3lxFgH8f51OrYTx2DVxSxCCXgqHq+Yc6nGSrfkejZADpChAy/CFo8MiN53Se5QshOrAjylP74qIPjtGz8bag==",
"type": "package",
"path": "Polly/5.0.3",
"files": [
"Polly.5.0.3.nupkg.sha512",
"Polly.nuspec",
"lib/net45/Polly.XML",
"lib/net45/Polly.dll",
"lib/net45/Polly.pdb",
"lib/netstandard1.0/Polly.XML",
"lib/netstandard1.0/Polly.dll",
"lib/netstandard1.0/Polly.pdb"
]
},
"runtime.any.System.Collections/4.3.0": {
"sha512": "23g6rqftKmovn2cLeGsuHUYm0FD7pdutb0uQMJpZ3qTvq+zHkgmt6J65VtRry4WDGYlmkMa4xDACtaQ94alNag==",
"type": "package",
Expand Down
21 changes: 16 additions & 5 deletions src/SfRestApi/Endpoints/ImageStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,22 @@
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.AspNetCore.WebUtilities;
using Polly;
using Polly.Retry;
using SfRestApi.Cluster;

namespace SfRestApi.Endpoints
{
public class ImageStore : BaseEndpoint
{
private readonly RetryPolicy<HttpResponseMessage> retryPolicy;

public ImageStore(IClusterConnection clusterConnection, ILogOutput logger)
: base(clusterConnection, logger)
{
retryPolicy = Policy
.HandleResult<HttpResponseMessage>(r => !r.IsSuccessStatusCode)
.WaitAndRetryAsync(5, i => TimeSpan.FromSeconds(Math.Pow(2, i)));
}

public async Task DeleteAsync(string packageName)
Expand Down Expand Up @@ -59,7 +66,7 @@ public async Task ListAsync(string packageName = null)
Console.WriteLine(ex.Message);
}
}

public async Task<bool> UploadAsync(FileInfo file, string fileInImageStore, string appPackagePathInStore)
{
try
Expand All @@ -83,7 +90,9 @@ public async Task<bool> UploadAsync(FileInfo file, string fileInImageStore, stri
}
else
{
using (var sourceStream = new FileStream(file.FullName, FileMode.Open, FileAccess.Read, FileShare.None))
using (
var sourceStream = new FileStream(file.FullName, FileMode.Open, FileAccess.Read, FileShare.None)
)
{
var data = new byte[file.Length];
await sourceStream.ReadAsync(data, 0, data.Length).ConfigureAwait(false);
Expand All @@ -92,10 +101,12 @@ public async Task<bool> UploadAsync(FileInfo file, string fileInImageStore, stri
}

Logger.Log($"Uploading {file.FullName} as {fileRelativePath}");
var repsonse = await ClusterConnection.HttpClient.PutAsync(requestUri, byteContent).ConfigureAwait(false);

repsonse.EnsureSuccessStatusCode();
return true;
var response = await retryPolicy
.ExecuteAsync(() => ClusterConnection.HttpClient.PutAsync(requestUri, byteContent))
.ConfigureAwait(false);

return response.IsSuccessStatusCode;
}
catch (Exception ex)
{
Expand Down
1 change: 1 addition & 0 deletions src/SfRestApi/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"Microsoft.AspNetCore.WebUtilities": "1.0.0",
"NETStandard.Library": "1.6.0",
"Newtonsoft.Json": "9.0.1",
"Polly": "5.0.3",
"System.Net.Http": "4.1.0"
},

Expand Down
28 changes: 28 additions & 0 deletions src/SfRestApi/project.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,18 @@
"lib/netstandard1.0/Newtonsoft.Json.dll": {}
}
},
"Polly/5.0.3": {
"type": "package",
"dependencies": {
"NETStandard.Library": "1.6.0"
},
"compile": {
"lib/netstandard1.0/Polly.dll": {}
},
"runtime": {
"lib/netstandard1.0/Polly.dll": {}
}
},
"runtime.native.System/4.0.0": {
"type": "package",
"dependencies": {
Expand Down Expand Up @@ -1396,6 +1408,21 @@
"tools/install.ps1"
]
},
"Polly/5.0.3": {
"sha512": "Kg3lxFgH8f51OrYTx2DVxSxCCXgqHq+Yc6nGSrfkejZADpChAy/CFo8MiN53Se5QshOrAjylP74qIPjtGz8bag==",
"type": "package",
"path": "Polly/5.0.3",
"files": [
"Polly.5.0.3.nupkg.sha512",
"Polly.nuspec",
"lib/net45/Polly.XML",
"lib/net45/Polly.dll",
"lib/net45/Polly.pdb",
"lib/netstandard1.0/Polly.XML",
"lib/netstandard1.0/Polly.dll",
"lib/netstandard1.0/Polly.pdb"
]
},
"runtime.native.System/4.0.0": {
"sha512": "QfS/nQI7k/BLgmLrw7qm7YBoULEvgWnPI+cYsbfCVFTW8Aj+i8JhccxcFMu1RWms0YZzF+UHguNBK4Qn89e2Sg==",
"type": "package",
Expand Down Expand Up @@ -4425,6 +4452,7 @@
"Microsoft.AspNetCore.WebUtilities >= 1.0.0",
"NETStandard.Library >= 1.6.0",
"Newtonsoft.Json >= 9.0.1",
"Polly >= 5.0.3",
"System.Net.Http >= 4.1.0"
],
".NETStandard,Version=v1.6": []
Expand Down

0 comments on commit 1d87df7

Please sign in to comment.