-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathBookSequentialOrchestration.cs
More file actions
63 lines (52 loc) · 1.8 KB
/
BookSequentialOrchestration.cs
File metadata and controls
63 lines (52 loc) · 1.8 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
using LLL.DurableTask.Worker;
using LLL.DurableTask.Worker.Attributes;
using static OrchestrationWorker.Orchestrations.BookSequentialOrchestration;
namespace OrchestrationWorker.Orchestrations;
[Orchestration(Name = "BookSequential", Version = "v1")]
public class BookSequentialOrchestration : OrchestrationBase<BookSequentialResult, BookSequentialInput>
{
public override async Task<BookSequentialResult> Execute(BookSequentialInput input)
{
var compensations = new List<Func<Task>>();
try
{
var bookCarResult = await Context.ScheduleTask<BookItemResult>("BookCar", "v1");
compensations.Add(() => Context.ScheduleTask<CancelItemResult>("CancelCar", "v1", new
{
bookCarResult.BookingId
}));
var bookHotelResult = await Context.ScheduleTask<BookItemResult>("BookHotel", "v1");
compensations.Add(() => Context.ScheduleTask<CancelItemResult>("CancelHotel", "v1", new
{
bookHotelResult.BookingId
}));
var bookFlightResult = await Context.ScheduleTask<BookItemResult>("BookFlight", "v1");
compensations.Add(() => Context.ScheduleTask<CancelItemResult>("CancelFlight", "v1", new
{
bookFlightResult.BookingId
}));
throw new Exception("Something failed");
}
catch
{
foreach (var compensation in compensations)
{
await compensation();
}
}
return new BookSequentialResult();
}
public class BookSequentialInput
{
}
public class BookSequentialResult
{
}
public class BookItemResult
{
public Guid BookingId { get; set; }
}
public class CancelItemResult
{
}
}