-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathBookParallelOrchestration.cs
More file actions
72 lines (60 loc) · 2.11 KB
/
BookParallelOrchestration.cs
File metadata and controls
72 lines (60 loc) · 2.11 KB
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
68
69
70
71
72
using LLL.DurableTask.Worker;
using LLL.DurableTask.Worker.Attributes;
using static OrchestrationWorker.Orchestrations.BookParallelOrchestration;
namespace OrchestrationWorker.Orchestrations;
[Orchestration(Name = "BookParallel", Version = "v1")]
public class BookParallelOrchestration : OrchestrationBase<BookParallelResult, BookParallelInput>
{
public override async Task<BookParallelResult> Execute(BookParallelInput input)
{
var compensations = new List<Func<Task>>();
try
{
var tasks = new List<Task>();
tasks.Add(new Func<Task>(async () =>
{
var bookCarResult = await Context.ScheduleTask<BookItemResult>("BookCar", "v1");
compensations.Add(() => Context.ScheduleTask<CancelItemResult>("CancelCar", "v1", new
{
bookCarResult.BookingId
}));
})());
tasks.Add(new Func<Task>(async () =>
{
var bookHotelResult = await Context.ScheduleTask<BookItemResult>("BookHotel", "v1");
compensations.Add(() => Context.ScheduleTask<CancelItemResult>("CancelHotel", "v1", new
{
bookHotelResult.BookingId
}));
})());
tasks.Add(new Func<Task>(async () =>
{
var bookFlightResult = await Context.ScheduleTask<BookItemResult>("BookFlight", "v1");
compensations.Add(() => Context.ScheduleTask<CancelItemResult>("CancelFlight", "v1", new
{
bookFlightResult.BookingId
}));
})());
await Task.WhenAll(tasks);
throw new Exception("Something failed");
}
catch
{
await Task.WhenAll(compensations.Select(c => c()));
}
return new BookParallelResult();
}
public class BookParallelInput
{
}
public class BookParallelResult
{
}
public class BookItemResult
{
public Guid BookingId { get; set; }
}
public class CancelItemResult
{
}
}