-
Notifications
You must be signed in to change notification settings - Fork 0
/
DurableFunctionsOrchestration.cs
67 lines (58 loc) · 2.26 KB
/
DurableFunctionsOrchestration.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.ApplicationInsights;
using Microsoft.ApplicationInsights.DataContracts;
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.DurableTask;
using Microsoft.Extensions.Logging;
namespace Company.Function
{
public static class DurableFunctionsOrchestration
{
[FunctionName("TimerOrchestrator")]
public static async Task TimerOrchestrator([TimerTrigger("0 */1 * * * *")] TimerInfo timer, [DurableClient] IDurableOrchestrationClient starter)
{
await starter.StartNewAsync("RunOrchestrator", null);
}
[FunctionName("RunOrchestrator")]
public static async Task RunOrchestrator(
[OrchestrationTrigger] IDurableOrchestrationContext context)
{
List<Task> activities = new List<Task>();
activities.Add(context.CallActivityAsync("TestUri", "https://www.bing.com/"));
activities.Add(context.CallActivityAsync("TestUri", "https://www.google.com/"));
await Task.WhenAll(activities);
}
[FunctionName("TestUri")]
public static async Task TestUri([ActivityTrigger] Uri test, ILogger log)
{
var telemetryClient = new TelemetryClient(new TelemetryConfiguration(Environment.GetEnvironmentVariable("APPINSIGHTS_INSTRUMENTATIONKEY")));
var telemetry = new AvailabilityTelemetry();
telemetry.Name = test.Host;
var watch = new Stopwatch();
try
{
HttpClient client = HttpClientFactory.Create();
watch.Start();
var responseMessage = await client.GetAsync(test);
responseMessage.EnsureSuccessStatusCode();
telemetry.Success = true;
}
catch (Exception e)
{
telemetry.Message = e.ToString();
}
finally
{
watch.Stop();
telemetry.Duration = watch.Elapsed;
telemetryClient.TrackAvailability(telemetry);
telemetryClient.Flush();
}
}
}
}