Skip to content

Commit

Permalink
Merge pull request #65 from shibayan/feature/retry
Browse files Browse the repository at this point in the history
Improvement retry strategy
  • Loading branch information
shibayan authored Mar 25, 2019
2 parents 0aff5fa + 4e51eb6 commit 2e29e86
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
13 changes: 10 additions & 3 deletions AzureAppService.LetsEncrypt/AddCertificate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

using ACMESharp.Protocol;

using AzureAppService.LetsEncrypt.Internal;

using Microsoft.Azure.Management.WebSites.Models;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
Expand Down Expand Up @@ -70,7 +72,7 @@ public static async Task RunOrchestrator([OrchestrationTrigger] DurableOrchestra
var result = await context.CallActivityAsync<ChallengeResult>(nameof(SharedFunctions.Dns01Authorization), authorization);

// Azure DNS で正しくレコードが引けるか確認
await context.CallActivityWithRetryAsync(nameof(SharedFunctions.CheckDnsChallenge), new RetryOptions(TimeSpan.FromSeconds(10), 6), result);
await context.CallActivityWithRetryAsync(nameof(SharedFunctions.CheckDnsChallenge), new RetryOptions(TimeSpan.FromSeconds(10), 6) { Handle = HandleRetriableException }, result);

challenges.Add(result);
}
Expand All @@ -80,7 +82,7 @@ public static async Task RunOrchestrator([OrchestrationTrigger] DurableOrchestra
var result = await context.CallActivityAsync<ChallengeResult>(nameof(SharedFunctions.Http01Authorization), (site, authorization));

// HTTP で正しくアクセスできるか確認
await context.CallActivityWithRetryAsync(nameof(SharedFunctions.CheckHttpChallenge), new RetryOptions(TimeSpan.FromSeconds(10), 6), result);
await context.CallActivityWithRetryAsync(nameof(SharedFunctions.CheckHttpChallenge), new RetryOptions(TimeSpan.FromSeconds(10), 6) { Handle = HandleRetriableException }, result);

challenges.Add(result);
}
Expand All @@ -90,7 +92,7 @@ public static async Task RunOrchestrator([OrchestrationTrigger] DurableOrchestra
await context.CallActivityAsync(nameof(SharedFunctions.AnswerChallenges), challenges);

// Order のステータスが ready になるまで 60 秒待機
await context.CallActivityWithRetryAsync(nameof(SharedFunctions.CheckIsReady), new RetryOptions(TimeSpan.FromSeconds(5), 12), orderDetails);
await context.CallActivityWithRetryAsync(nameof(SharedFunctions.CheckIsReady), new RetryOptions(TimeSpan.FromSeconds(5), 12) { Handle = HandleRetriableException }, orderDetails);

// Order の最終処理を実行し PFX を作成
var (thumbprint, pfxBlob) = await context.CallActivityAsync<(string, byte[])>(nameof(SharedFunctions.FinalizeOrder), (request.Domains, orderDetails));
Expand Down Expand Up @@ -142,6 +144,11 @@ public static async Task<HttpResponseMessage> HttpStart(

return await starter.WaitForCompletionOrCreateCheckStatusResponseAsync(req, instanceId, TimeSpan.FromMinutes(5));
}

private static bool HandleRetriableException(Exception exception)
{
return exception.InnerException is RetriableActivityException;
}
}

public class AddCertificateRequest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
<PackageReference Include="Microsoft.Azure.Management.Dns" Version="3.0.1" />
<PackageReference Include="Microsoft.Azure.Management.WebSites" Version="2.0.1" />
<PackageReference Include="Microsoft.Azure.Services.AppAuthentication" Version="1.0.3" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.DurableTask" Version="1.7.1" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.25" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.DurableTask" Version="1.8.0" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.26" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
Expand Down
13 changes: 10 additions & 3 deletions AzureAppService.LetsEncrypt/RenewCertificates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

using ACMESharp.Protocol;

using AzureAppService.LetsEncrypt.Internal;

using Microsoft.Azure.Management.WebSites.Models;
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;
Expand Down Expand Up @@ -96,7 +98,7 @@ public static async Task RenewSiteCertificates([OrchestrationTrigger] DurableOrc
var result = await context.CallActivityAsync<ChallengeResult>(nameof(SharedFunctions.Dns01Authorization), authorization);

// Azure DNS で正しくレコードが引けるか確認
await context.CallActivityWithRetryAsync(nameof(SharedFunctions.CheckDnsChallenge), new RetryOptions(TimeSpan.FromSeconds(10), 6), result);
await context.CallActivityWithRetryAsync(nameof(SharedFunctions.CheckDnsChallenge), new RetryOptions(TimeSpan.FromSeconds(10), 6) { Handle = HandleRetriableException }, result);

challenges.Add(result);
}
Expand All @@ -105,7 +107,7 @@ public static async Task RenewSiteCertificates([OrchestrationTrigger] DurableOrc
var result = await context.CallActivityAsync<ChallengeResult>(nameof(SharedFunctions.Http01Authorization), (site, authorization));

// HTTP で正しくアクセスできるか確認
await context.CallActivityWithRetryAsync(nameof(SharedFunctions.CheckHttpChallenge), new RetryOptions(TimeSpan.FromSeconds(10), 6), result);
await context.CallActivityWithRetryAsync(nameof(SharedFunctions.CheckHttpChallenge), new RetryOptions(TimeSpan.FromSeconds(10), 6) { Handle = HandleRetriableException }, result);

challenges.Add(result);
}
Expand All @@ -115,7 +117,7 @@ public static async Task RenewSiteCertificates([OrchestrationTrigger] DurableOrc
await context.CallActivityAsync(nameof(SharedFunctions.AnswerChallenges), challenges);

// Order のステータスが ready になるまで 60 秒待機
await context.CallActivityWithRetryAsync(nameof(SharedFunctions.CheckIsReady), new RetryOptions(TimeSpan.FromSeconds(5), 12), orderDetails);
await context.CallActivityWithRetryAsync(nameof(SharedFunctions.CheckIsReady), new RetryOptions(TimeSpan.FromSeconds(5), 12) { Handle = HandleRetriableException }, orderDetails);

// Order の最終処理を実行し PFX を作成
var (thumbprint, pfxBlob) = await context.CallActivityAsync<(string, byte[])>(nameof(SharedFunctions.FinalizeOrder), (certificate.HostNames, orderDetails));
Expand All @@ -140,5 +142,10 @@ public static async Task TimerStart([TimerTrigger("0 0 0 * * *")] TimerInfo time

log.LogInformation($"Started orchestration with ID = '{instanceId}'.");
}

private static bool HandleRetriableException(Exception exception)
{
return exception.InnerException is RetriableActivityException;
}
}
}

0 comments on commit 2e29e86

Please sign in to comment.