-
Notifications
You must be signed in to change notification settings - Fork 13
/
GetPlanetResidentsOrchestrator.cs
50 lines (42 loc) · 1.61 KB
/
GetPlanetResidentsOrchestrator.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
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using DurableFunctions.Demo.DotNetCore.FanOutFanIn.Activities;
using DurableFunctions.Demo.DotNetCore.FanOutFanIn.Orchestrators.Models;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.DurableTask;
using Microsoft.Extensions.Logging;
// ReSharper disable once CheckNamespace
namespace DurableFunctions.Demo.DotNetCore.FanOutFanIn.Orchestrators
{
public class GetPlanetResidentsOrchestrator
{
[FunctionName(nameof(GetPlanetResidentsOrchestrator))]
public async Task<PlanetResidents> Run(
[OrchestrationTrigger]IDurableOrchestrationContext context,
ILogger log)
{
var planetName = context.GetInput<string>();
var result = new PlanetResidents();
var planetResult = await context.CallActivityAsync<Planet>(
nameof(SearchPlanetActivity),
planetName);
if (planetResult != null)
{
result.PlanetName = planetResult.Name;
var tasks = new List<Task<string>>();
foreach (var residentUrl in planetResult.ResidentUrls)
{
tasks.Add(
context.CallActivityAsync<string>(
nameof(GetCharacterActivity),
residentUrl)
);
}
await Task.WhenAll(tasks);
result.Residents = tasks.Select(task => task.Result).ToArray();
}
return result;
}
}
}