Skip to content

Commit 4fd6d46

Browse files
committed
fix
1 parent 19a8d8d commit 4fd6d46

File tree

4 files changed

+61
-7
lines changed

4 files changed

+61
-7
lines changed

samples/ExceptionPropertiesSample/ExceptionPropertiesSample.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
<ItemGroup>
2020
<!-- Using p2p references so we can show latest changes in samples. -->
2121
<ProjectReference Include="$(SrcRoot)Client/Grpc/Client.Grpc.csproj" />
22+
<ProjectReference Include="$(SrcRoot)Client/AzureManaged/Client.AzureManaged.csproj" />
2223
<ProjectReference Include="$(SrcRoot)Worker/Grpc/Worker.Grpc.csproj" />
24+
<ProjectReference Include="$(SrcRoot)Worker/AzureManaged/Worker.AzureManaged.csproj" />
2325
</ItemGroup>
2426

2527
</Project>

samples/ExceptionPropertiesSample/Program.cs

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,53 @@
55
// TaskFailureDetails with custom exception properties for better diagnostics.
66

77
using ExceptionPropertiesSample;
8+
using Microsoft.Extensions.Configuration;
9+
using Microsoft.Extensions.DependencyInjection;
810
using Microsoft.DurableTask.Client;
11+
using Microsoft.DurableTask.Client.AzureManaged;
912
using Microsoft.DurableTask.Worker;
13+
using Microsoft.DurableTask.Worker.AzureManaged;
1014
using Microsoft.Extensions.Hosting;
1115

1216
HostApplicationBuilder builder = Host.CreateApplicationBuilder(args);
1317

18+
string? schedulerConnectionString = builder.Configuration.GetValue<string>("DURABLE_TASK_SCHEDULER_CONNECTION_STRING");
19+
bool useScheduler = !string.IsNullOrWhiteSpace(schedulerConnectionString);
20+
1421
// 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+
}
1630

1731
// 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 =>
2035
{
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+
}
2555

2656
// Register the custom exception properties provider
2757
// This will automatically extract custom properties from exceptions and include them in TaskFailureDetails
@@ -39,6 +69,11 @@
3969
Console.WriteLine("===========================");
4070
Console.WriteLine();
4171

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+
4277
// Test case 1: Valid input (should succeed)
4378
Console.WriteLine("Test 1: Valid input");
4479
string instanceId1 = await client.ScheduleNewOrchestrationInstanceAsync(

samples/ExceptionPropertiesSample/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,20 @@ When orchestrations or activities throw exceptions, the Durable Task framework c
2222

2323
## Running the Sample
2424

25+
This sample can run against either:
26+
27+
1. **Durable Task Scheduler (DTS)** (recommended): set the `DURABLE_TASK_SCHEDULER_CONNECTION_STRING` environment variable.
28+
2. **Local gRPC endpoint**: if the env var is not set, the sample uses the default local gRPC configuration.
29+
30+
### DTS
31+
32+
Set `DURABLE_TASK_SCHEDULER_CONNECTION_STRING` and run the sample.
33+
34+
```cmd
35+
set DURABLE_TASK_SCHEDULER_CONNECTION_STRING=Endpoint=https://...;TaskHub=...;Authentication=...;
36+
dotnet run --project ExceptionPropertiesSample
37+
```
38+
2539
```bash
2640
dotnet run --project ExceptionPropertiesSample
2741
```
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"DURABLE_TASK_SCHEDULER_CONNECTION_STRING": ""
3+
}

0 commit comments

Comments
 (0)