Skip to content

Commit 6529d09

Browse files
Add polly retry to get artifact URL from DevOps (#8112)
* Add polly retry to get artifact URL from DevOps
1 parent 2fa41b4 commit 6529d09

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

src/dotnet/APIView/APIViewWeb/Repositories/DevopsArtifactRepository.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,25 @@ public async Task<Stream> DownloadPackageArtifact(string repoName, string buildI
5656

5757
private async Task<string> getDownloadArtifactUrl(string buildId, string artifactName, string project)
5858
{
59+
var pauseBetweenFailures = TimeSpan.FromSeconds(2);
60+
var retryPolicy = Policy
61+
.Handle<HttpRequestException>()
62+
.WaitAndRetryAsync(5, i => pauseBetweenFailures);
63+
5964
var connection = await CreateVssConnection();
6065
var buildClient = connection.GetClient<BuildHttpClient>();
61-
var artifact = await buildClient.GetArtifactAsync(project, int.Parse(buildId), artifactName);
62-
return artifact?.Resource?.DownloadUrl;
66+
string url = null;
67+
await retryPolicy.ExecuteAsync(async () =>
68+
{
69+
var artifact = await buildClient.GetArtifactAsync(project, int.Parse(buildId), artifactName);
70+
url = artifact?.Resource?.DownloadUrl;
71+
});
72+
73+
if (string.IsNullOrEmpty(url))
74+
{
75+
throw new Exception(string.Format("Failed to get download url for artifact {0} in build {1} in project {2}", artifactName, buildId, project));
76+
}
77+
return url;
6378
}
6479

6580
private async Task<VssConnection> CreateVssConnection()

0 commit comments

Comments
 (0)