|
8 | 8 | using Microsoft.Extensions.DependencyInjection; |
9 | 9 | using Microsoft.Extensions.Hosting; |
10 | 10 | using Microsoft.Extensions.Logging; |
| 11 | +using ScheduleDemo.Activities; |
| 12 | + |
11 | 13 |
|
12 | 14 | // Create the host builder |
13 | 15 | IHost host = Host.CreateDefaultBuilder(args) |
|
22 | 24 | // Add the Schedule entity and demo orchestration |
23 | 25 | builder.AddTasks(r => |
24 | 26 | { |
25 | | - // Add a demo orchestration that will be triggered by the schedule |
26 | | - r.AddOrchestratorFunc<string, string>("DemoOrchestration", async (context, symbol) => |
27 | | - { |
28 | | - var logger = context.CreateReplaySafeLogger("DemoOrchestration"); |
29 | | - logger.LogInformation("Getting stock price for: {symbol}", symbol); |
30 | | - try |
31 | | - { |
32 | | - // Get current stock price |
33 | | - decimal currentPrice = await context.CallActivityAsync<decimal>("GetStockPrice", symbol); |
34 | | - |
35 | | - logger.LogInformation("Current price for {symbol} is ${price:F2}", symbol, currentPrice); |
36 | | - |
37 | | - return $"Stock {symbol} price: ${currentPrice:F2} at {DateTime.UtcNow}"; |
38 | | - } |
39 | | - catch (Exception ex) |
40 | | - { |
41 | | - logger.LogError(ex, "Error processing stock price for {symbol}", symbol); |
42 | | - throw; |
43 | | - } |
44 | | - }); |
| 27 | + // Add the orchestrator class |
| 28 | + r.AddOrchestrator<StockPriceOrchestrator>(); |
45 | 29 |
|
46 | 30 | // Add required activities |
47 | | - r.AddActivityFunc<string, decimal>("GetStockPrice", (context, symbol) => |
48 | | - { |
49 | | - // Mock implementation - would normally call stock API |
50 | | - return 100.00m; |
51 | | - }); |
| 31 | + r.AddActivity<GetStockPrice>(); |
52 | 32 | }); |
53 | 33 |
|
54 | 34 | // Enable scheduled tasks support |
|
94 | 74 | // Create schedule options that runs every 30 seconds |
95 | 75 | ScheduleCreationOptions scheduleOptions = new ScheduleCreationOptions |
96 | 76 | { |
97 | | - OrchestrationName = "DemoOrchestration", |
| 77 | + OrchestrationName = nameof(StockPriceOrchestrator), |
98 | 78 | ScheduleId = "demo-schedule101", |
99 | 79 | Interval = TimeSpan.FromSeconds(4), |
100 | 80 | StartAt = DateTimeOffset.UtcNow, |
|
136 | 116 | Console.WriteLine(""); |
137 | 117 | Console.WriteLine(""); |
138 | 118 |
|
139 | | - await Task.Delay(2000000); |
| 119 | + await Task.Delay(TimeSpan.FromMinutes(30)); |
140 | 120 | //Console.WriteLine("\nPress any key to delete the schedule and exit..."); |
141 | 121 | //Console.ReadKey(); |
142 | 122 |
|
|
0 commit comments