Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding notification if orchestrator failure #67

Merged
merged 2 commits into from
Mar 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions AzureAppService.LetsEncrypt/GetSitesInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public static async Task<IList<ResourceGroupInformation>> RunOrchestrator([Orche
result.Add(resourceGroup);
}
}

return result;
}

Expand Down Expand Up @@ -120,6 +120,6 @@ public class SlotInformation
public string Name { get; set; }

[JsonProperty("domains")]
public IList<string> Domains{ get; set; }
public IList<string> Domains { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using System.Net.Http;
using System.Threading.Tasks;

using Microsoft.Azure.WebJobs.Extensions.DurableTask;

namespace AzureAppService.LetsEncrypt.Internal
{
internal class InProcLifeCycleNotificationHelper : ILifeCycleNotificationHelper
{
public Task OrchestratorStartingAsync(string hubName, string functionName, string instanceId, bool isReplay)
{
return Task.CompletedTask;
}

public Task OrchestratorCompletedAsync(string hubName, string functionName, string instanceId, bool continuedAsNew, bool isReplay)
{
return Task.CompletedTask;
}

public async Task OrchestratorFailedAsync(string hubName, string functionName, string instanceId, string reason, bool isReplay)
{
await PostEventAsync(functionName, instanceId, reason);
}

public Task OrchestratorTerminatedAsync(string hubName, string functionName, string instanceId, string reason)
{
return Task.CompletedTask;
}

private static readonly HttpClient _httpClient = new HttpClient();

private static async Task PostEventAsync(string functionName, string instanceId, string reason)
{
if (string.IsNullOrEmpty(Settings.Default.Webhook))
{
return;
}

object model;

if (Settings.Default.Webhook.Contains("hooks.slack.com"))
{
model = new
{
attachments = new[]
{
new
{
title = functionName,
text = reason,
color = "danger"
}
}
};
}
else
{
model = new
{
functionName,
instanceId,
reason
};
}

await _httpClient.PostAsJsonAsync(Settings.Default.Webhook, model);
}
}
}
2 changes: 2 additions & 0 deletions AzureAppService.LetsEncrypt/Internal/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public Settings()

public string SubscriptionId => _section[nameof(SubscriptionId)];

public string Webhook => _section[nameof(Webhook)];

public static Settings Default { get; } = new Settings();
}
}
3 changes: 2 additions & 1 deletion AzureAppService.LetsEncrypt/host.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"extensions": {
"durableTask": {
"extendedSessionsEnabled": true,
"extendedSessionIdleTimeoutInSeconds": 30
"extendedSessionIdleTimeoutInSeconds": 30,
"CustomLifeCycleNotificationHelperType": "AzureAppService.LetsEncrypt.Internal.InProcLifeCycleNotificationHelper, AzureAppService.LetsEncrypt"
}
}
}
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ They can manage multiple App Service certificates with simple one Functions.
- Azure Subscription Id
- LetsEncrypt:Contacts
- Email address for Let's Encrypt account
- LetsEncrypt:Webhook
- Webhook destination URL (optional, Slack recommend)

### 3. Enable App Service Authentication (EasyAuth) with AAD

Expand Down