Skip to content

Commit 78a46df

Browse files
authored
Add New Property Properties to TaskOrchestrationContext (#415)
* initial commit * sort usings * update summary and also properties * update changelog and update comments * udpate by comment * pull latest protobuf * update by comment and also fix some warnings * remove default settings * update by reviews
1 parent 609336e commit 78a46df

File tree

13 files changed

+113
-8
lines changed

13 files changed

+113
-8
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
## (Unreleased)
44

5-
- Add automatic retry on gateway timeout in `GrpcDurableTaskClient.WaitForInstanceCompletionAsync` in ([#412](https://github.com/microsoft/durabletask-dotnet/pull/412))
5+
- Add New Property Properties to TaskOrchestrationContext by @nytian in [#415](https://github.com/microsoft/durabletask-dotnet/pull/415)
6+
- Add automatic retry on gateway timeout in `GrpcDurableTaskClient.WaitForInstanceCompletionAsync` in [#412](https://github.com/microsoft/durabletask-dotnet/pull/412))
67
- Add specific logging for NotFound error on worker connection by @halspang in ([#413](https://github.com/microsoft/durabletask-dotnet/pull/413))
78
- Add user agent header to gRPC called in ([#417](https://github.com/microsoft/durabletask-dotnet/pull/417))
89
- Enrich User-Agent Header in gRPC Metadata to indicate Client or Worker as caller ([#421](https://github.com/microsoft/durabletask-dotnet/pull/421))

src/Abstractions/TaskOrchestrationContext.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ public abstract class TaskOrchestrationContext
6565
/// </summary>
6666
public virtual string Version => string.Empty;
6767

68+
/// <summary>
69+
/// Gets the configuration settings for the orchestration context.
70+
/// </summary>
71+
public virtual IReadOnlyDictionary<string, object?> Properties { get; } = new Dictionary<string, object?>();
72+
6873
/// <summary>
6974
/// Gets the entity feature, for interacting with entities.
7075
/// </summary>

src/Grpc/orchestrator_service.proto

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import "google/protobuf/timestamp.proto";
1111
import "google/protobuf/duration.proto";
1212
import "google/protobuf/wrappers.proto";
1313
import "google/protobuf/empty.proto";
14+
import "google/protobuf/struct.proto";
1415

1516
message OrchestrationInstance {
1617
string instanceId = 1;
@@ -318,6 +319,7 @@ message OrchestratorRequest {
318319
repeated HistoryEvent newEvents = 4;
319320
OrchestratorEntityParameters entityParameters = 5;
320321
bool requiresHistoryStreaming = 6;
322+
map<string, google.protobuf.Value> properties = 7;
321323
}
322324

323325
message OrchestratorResponse {

src/Grpc/versions.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
# The following files were downloaded from branch main at 2025-03-24 23:37:31 UTC
2-
https://raw.githubusercontent.com/microsoft/durabletask-protobuf/c85ef11430ff8e10e21105abb545b0803bb86c66/protos/orchestrator_service.proto
1+
# The following files were downloaded from branch main at 2025-04-23 23:27:00 UTC
2+
https://raw.githubusercontent.com/microsoft/durabletask-protobuf/fbe5bb20835678099fc51a44993ed9b045dee5a6/protos/orchestrator_service.proto

src/ScheduledTasks/Client/ScheduledTaskClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace Microsoft.DurableTask.ScheduledTasks;
55

66
/// <summary>
77
/// Client for managing scheduled tasks.
8-
/// Provides methods to retrieve a ScheduleClient, list all schedules,
8+
/// Provides methods to retrieve a ScheduleClient, list all schedules,
99
/// and get details of a specific schedule.
1010
/// </summary>
1111
public abstract class ScheduledTaskClient

src/ScheduledTasks/Models/ScheduleState.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,4 @@ public void RefreshScheduleRunExecutionToken()
5050
{
5151
this.ExecutionToken = Guid.NewGuid().ToString("N");
5252
}
53-
}
53+
}

src/Shared/AzureManaged/GrpcRetryPolicyDefaults.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ sealed class GrpcRetryPolicyDefaults
3939
/// </remarks>
4040
public static readonly ServiceConfig DefaultServiceConfig;
4141

42-
4342
/// <summary>
4443
/// The default retry policy for gRPC operations.
4544
/// </summary>

src/Shared/Grpc/ProtoUtils.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,37 @@ internal static T Base64Decode<T>(this MessageParser parser, string encodedMessa
904904
failureDetails.IsNonRetriable);
905905
}
906906

907+
/// <summary>
908+
/// Converts a <see cref="Google.Protobuf.WellKnownTypes.Value"/> instance to a corresponding C# object.
909+
/// </summary>
910+
/// <param name="value">The Protobuf Value to convert.</param>
911+
/// <returns>The corresponding C# object.</returns>
912+
/// <exception cref="NotSupportedException">
913+
/// Thrown when the Protobuf Value.KindCase is not one of the supported types.
914+
/// </exception>
915+
internal static object? ConvertValueToObject(Google.Protobuf.WellKnownTypes.Value value)
916+
{
917+
switch (value.KindCase)
918+
{
919+
case Google.Protobuf.WellKnownTypes.Value.KindOneofCase.NullValue:
920+
return null;
921+
case Google.Protobuf.WellKnownTypes.Value.KindOneofCase.NumberValue:
922+
return value.NumberValue;
923+
case Google.Protobuf.WellKnownTypes.Value.KindOneofCase.StringValue:
924+
return value.StringValue;
925+
case Google.Protobuf.WellKnownTypes.Value.KindOneofCase.BoolValue:
926+
return value.BoolValue;
927+
case Google.Protobuf.WellKnownTypes.Value.KindOneofCase.StructValue:
928+
return value.StructValue.Fields.ToDictionary(
929+
pair => pair.Key,
930+
pair => ConvertValueToObject(pair.Value));
931+
case Google.Protobuf.WellKnownTypes.Value.KindOneofCase.ListValue:
932+
return value.ListValue.Values.Select(ConvertValueToObject).ToList();
933+
default:
934+
throw new NotSupportedException($"Unsupported Value kind: {value.KindCase}");
935+
}
936+
}
937+
907938
/// <summary>
908939
/// Converts a <see cref="FailureDetails" /> to a grpc <see cref="P.TaskFailureDetails" />.
909940
/// </summary>

src/Worker/Core/Shims/DurableTaskShimFactory.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,29 @@ public TaskOrchestration CreateOrchestration(
8989
return new TaskOrchestrationShim(context, orchestrator);
9090
}
9191

92+
/// <summary>
93+
/// Creates a <see cref="TaskOrchestration" /> from a <see cref="ITaskOrchestrator" />.
94+
/// </summary>
95+
/// <param name="name">
96+
/// The name of the orchestration. This should be the name the orchestration was invoked with.
97+
/// </param>
98+
/// <param name="orchestrator">The orchestration to wrap.</param>
99+
/// <param name ="properties">Configuration for the orchestration.</param>
100+
/// <param name="parent">The orchestration parent details or <c>null</c> if no parent.</param>
101+
/// <returns>A new <see cref="TaskOrchestration" />.</returns>
102+
public TaskOrchestration CreateOrchestration(
103+
TaskName name,
104+
ITaskOrchestrator orchestrator,
105+
IReadOnlyDictionary<string, object?> properties,
106+
ParentOrchestrationInstance? parent = null)
107+
{
108+
Check.NotDefault(name);
109+
Check.NotNull(orchestrator);
110+
Check.NotNull(properties);
111+
OrchestrationInvocationContext context = new(name, this.options, this.loggerFactory, parent);
112+
return new TaskOrchestrationShim(context, orchestrator, properties);
113+
}
114+
92115
/// <summary>
93116
/// Creates a <see cref="TaskOrchestration" /> from a <see cref="ITaskOrchestrator" />.
94117
/// </summary>

src/Worker/Core/Shims/TaskOrchestrationContextWrapper.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,27 @@ public TaskOrchestrationContextWrapper(
3838
OrchestrationContext innerContext,
3939
OrchestrationInvocationContext invocationContext,
4040
object? deserializedInput)
41+
: this(innerContext, invocationContext, deserializedInput, new Dictionary<string, object?>())
42+
{
43+
}
44+
45+
/// <summary>
46+
/// Initializes a new instance of the <see cref="TaskOrchestrationContextWrapper"/> class.
47+
/// </summary>
48+
/// <param name="innerContext">The inner orchestration context.</param>
49+
/// <param name="invocationContext">The invocation context.</param>
50+
/// <param name="deserializedInput">The deserialized input.</param>
51+
/// <param name="properties">The configuration for context.</param>
52+
public TaskOrchestrationContextWrapper(
53+
OrchestrationContext innerContext,
54+
OrchestrationInvocationContext invocationContext,
55+
object? deserializedInput,
56+
IReadOnlyDictionary<string, object?> properties)
4157
{
4258
this.innerContext = Check.NotNull(innerContext);
4359
this.invocationContext = Check.NotNull(invocationContext);
60+
this.Properties = Check.NotNull(properties);
61+
4462
this.logger = this.CreateReplaySafeLogger("Microsoft.DurableTask");
4563
this.deserializedInput = deserializedInput;
4664
}
@@ -60,6 +78,11 @@ public TaskOrchestrationContextWrapper(
6078
/// <inheritdoc/>
6179
public override DateTime CurrentUtcDateTime => this.innerContext.CurrentUtcDateTime;
6280

81+
/// <summary>
82+
/// Gets the configuration settings for the orchestration.
83+
/// </summary>
84+
public override IReadOnlyDictionary<string, object?> Properties { get; }
85+
6386
/// <inheritdoc/>
6487
public override TaskOrchestrationEntityFeature Entities
6588
{

0 commit comments

Comments
 (0)