|
5 | 5 | // TaskFailureDetails with custom exception properties for better diagnostics. |
6 | 6 |
|
7 | 7 | using ExceptionPropertiesSample; |
| 8 | +using Microsoft.Extensions.Configuration; |
| 9 | +using Microsoft.Extensions.DependencyInjection; |
8 | 10 | using Microsoft.DurableTask.Client; |
| 11 | +using Microsoft.DurableTask.Client.AzureManaged; |
9 | 12 | using Microsoft.DurableTask.Worker; |
| 13 | +using Microsoft.DurableTask.Worker.AzureManaged; |
10 | 14 | using Microsoft.Extensions.Hosting; |
11 | 15 |
|
12 | 16 | HostApplicationBuilder builder = Host.CreateApplicationBuilder(args); |
13 | 17 |
|
| 18 | +string? schedulerConnectionString = builder.Configuration.GetValue<string>("DURABLE_TASK_SCHEDULER_CONNECTION_STRING"); |
| 19 | +bool useScheduler = !string.IsNullOrWhiteSpace(schedulerConnectionString); |
| 20 | + |
14 | 21 | // Register the durable task client |
15 | | -builder.Services.AddDurableTaskClient().UseGrpc(); |
| 22 | +if (useScheduler) |
| 23 | +{ |
| 24 | + builder.Services.AddDurableTaskClient(clientBuilder => clientBuilder.UseDurableTaskScheduler(schedulerConnectionString!)); |
| 25 | +} |
| 26 | +else |
| 27 | +{ |
| 28 | + builder.Services.AddDurableTaskClient().UseGrpc(); |
| 29 | +} |
16 | 30 |
|
17 | 31 | // Register the durable task worker with custom exception properties provider |
18 | | -builder.Services.AddDurableTaskWorker() |
19 | | - .AddTasks(tasks => |
| 32 | +if (useScheduler) |
| 33 | +{ |
| 34 | + builder.Services.AddDurableTaskWorker(workerBuilder => |
20 | 35 | { |
21 | | - tasks.AddOrchestrator<ValidationOrchestration>(); |
22 | | - tasks.AddActivity<ValidateInputActivity>(); |
23 | | - }) |
24 | | - .UseGrpc(); |
| 36 | + workerBuilder.AddTasks(tasks => |
| 37 | + { |
| 38 | + tasks.AddOrchestrator<ValidationOrchestration>(); |
| 39 | + tasks.AddActivity<ValidateInputActivity>(); |
| 40 | + }); |
| 41 | + |
| 42 | + workerBuilder.UseDurableTaskScheduler(schedulerConnectionString!); |
| 43 | + }); |
| 44 | +} |
| 45 | +else |
| 46 | +{ |
| 47 | + builder.Services.AddDurableTaskWorker() |
| 48 | + .AddTasks(tasks => |
| 49 | + { |
| 50 | + tasks.AddOrchestrator<ValidationOrchestration>(); |
| 51 | + tasks.AddActivity<ValidateInputActivity>(); |
| 52 | + }) |
| 53 | + .UseGrpc(); |
| 54 | +} |
25 | 55 |
|
26 | 56 | // Register the custom exception properties provider |
27 | 57 | // This will automatically extract custom properties from exceptions and include them in TaskFailureDetails |
|
39 | 69 | Console.WriteLine("==========================="); |
40 | 70 | Console.WriteLine(); |
41 | 71 |
|
| 72 | +Console.WriteLine(useScheduler |
| 73 | + ? "Configured to use Durable Task Scheduler (DTS)." |
| 74 | + : "Configured to use local gRPC. (Set DURABLE_TASK_SCHEDULER_CONNECTION_STRING to use DTS.)"); |
| 75 | +Console.WriteLine(); |
| 76 | + |
42 | 77 | // Test case 1: Valid input (should succeed) |
43 | 78 | Console.WriteLine("Test 1: Valid input"); |
44 | 79 | string instanceId1 = await client.ScheduleNewOrchestrationInstanceAsync( |
|
0 commit comments