Skip to content

Commit 3d4e485

Browse files
committed
update
2 parents c8ff67f + b217eb3 commit 3d4e485

File tree

10 files changed

+1317
-1278
lines changed

10 files changed

+1317
-1278
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
# Changelog
2+
3+
## v1.15.1 (Unreleased)
4+
- Add version check to activities by @halspang in ([#472](https://github.com/microsoft/durabletask-dotnet/pull/472))
5+
26
## v1.15.0
37
- Abandon workitem if processing workitem failed by @YunchuWang in ([#467](https://github.com/microsoft/durabletask-dotnet/pull/467))
48
- Extended Sessions for Isolated (Orchestrations) by @sophiatev in ([#449](https://github.com/microsoft/durabletask-dotnet/pull/449))

eng/targets/Release.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
</PropertyGroup>
1818

1919
<PropertyGroup>
20-
<VersionPrefix>1.15.0</VersionPrefix>
20+
<VersionPrefix>1.15.1</VersionPrefix>
2121
<VersionSuffix></VersionSuffix>
2222
</PropertyGroup>
2323

src/Abstractions/TaskFailureDetails.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace Microsoft.DurableTask;
1616
/// <param name="StackTrace">The stack trace of the failure.</param>
1717
/// <param name="InnerFailure">The inner cause of the task failure.</param>
1818
/// <param name="Properties">Additional properties associated with the exception.</param>
19-
public record TaskFailureDetails(string ErrorType, string ErrorMessage, string? StackTrace, TaskFailureDetails? InnerFailure, IDictionary<string, object>? Properties)
19+
public record TaskFailureDetails(string ErrorType, string ErrorMessage, string? StackTrace, TaskFailureDetails? InnerFailure, IDictionary<string, object?>? Properties)
2020
{
2121
Type? loadedExceptionType;
2222

src/Shared/Grpc/ProtoUtils.cs

Lines changed: 1248 additions & 1253 deletions
Large diffs are not rendered by default.

src/Worker/Core/IExceptionPropertiesProvider.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ namespace Microsoft.DurableTask.Worker;
66
/// <summary>
77
/// Provides custom exception property inclusion rules for enriching FailureDetails.
88
/// </summary>
9-
/// <remarks>
10-
/// Implementations should be thread-safe. The worker may call this for many exceptions concurrently.
11-
/// </remarks>
129
public interface IExceptionPropertiesProvider
1310
{
1411
/// <summary>

src/Worker/Core/Shims/DurableTaskShimFactory.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ public class DurableTaskShimFactory
2626
/// </summary>
2727
/// <param name="options">The data converter.</param>
2828
/// <param name="loggerFactory">The logger factory.</param>
29-
/// <param name="exceptionPropertiesProvider">Custom provider used to extract exception properties for inclusion in the failure details.</param>
3029
public DurableTaskShimFactory(
3130
DurableTaskWorkerOptions? options = null, ILoggerFactory? loggerFactory = null)
3231
{

src/Worker/Core/Shims/TaskOrchestrationContextWrapper.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public override async Task<T> CallActivityAsync<T>(
154154
{
155155
return await this.innerContext.ScheduleTask<T>(
156156
name.Name,
157-
name.Version,
157+
this.innerContext.Version,
158158
options: ScheduleTaskOptions.CreateBuilder()
159159
.WithRetryOptions(policy.ToDurableTaskCoreRetryOptions())
160160
.WithTags(tags)
@@ -166,7 +166,7 @@ public override async Task<T> CallActivityAsync<T>(
166166
return await this.InvokeWithCustomRetryHandler(
167167
() => this.innerContext.ScheduleTask<T>(
168168
name.Name,
169-
name.Version,
169+
this.innerContext.Version,
170170
options: ScheduleTaskOptions.CreateBuilder()
171171
.WithTags(tags)
172172
.Build(),
@@ -179,7 +179,7 @@ public override async Task<T> CallActivityAsync<T>(
179179
{
180180
return await this.innerContext.ScheduleTask<T>(
181181
name.Name,
182-
name.Version,
182+
this.innerContext.Version,
183183
options: ScheduleTaskOptions.CreateBuilder()
184184
.WithTags(tags)
185185
.Build(),

src/Worker/Grpc/GrpcDurableTaskWorker.Processor.cs

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class Processor
3333
readonly TaskHubSidecarServiceClient client;
3434
readonly DurableTaskShimFactory shimFactory;
3535
readonly GrpcDurableTaskWorkerOptions.InternalOptions internalOptions;
36-
readonly DTCore.IExceptionPropertiesProvider exceptionPropertiesProvider;
36+
readonly DTCore.IExceptionPropertiesProvider? exceptionPropertiesProvider;
3737
[Obsolete("Experimental")]
3838
readonly IOrchestrationFilter? orchestrationFilter;
3939

@@ -44,7 +44,7 @@ public Processor(GrpcDurableTaskWorker worker, TaskHubSidecarServiceClient clien
4444
this.shimFactory = new DurableTaskShimFactory(this.worker.grpcOptions, this.worker.loggerFactory);
4545
this.internalOptions = this.worker.grpcOptions.Internal;
4646
this.orchestrationFilter = orchestrationFilter;
47-
this.exceptionPropertiesProvider = exceptionPropertiesProvider != null
47+
this.exceptionPropertiesProvider = exceptionPropertiesProvider is not null
4848
? new ExceptionPropertiesProviderAdapter(exceptionPropertiesProvider)
4949
: null;
5050
}
@@ -764,16 +764,60 @@ async Task OnRunActivityAsync(P.ActivityRequest request, string completionToken,
764764

765765
OrchestrationInstance instance = request.OrchestrationInstance.ToCore();
766766
string rawInput = request.Input;
767-
768767
int inputSize = rawInput != null ? Encoding.UTF8.GetByteCount(rawInput) : 0;
769768
this.Logger.ReceivedActivityRequest(request.Name, request.TaskId, instance.InstanceId, inputSize);
770769

770+
P.TaskFailureDetails? failureDetails = null;
771771
TaskContext innerContext = new(instance);
772772
innerContext.ExceptionPropertiesProvider = this.exceptionPropertiesProvider;
773773

774774
TaskName name = new(request.Name);
775775
string? output = null;
776-
P.TaskFailureDetails? failureDetails = null;
776+
777+
failureDetails = EvaluateOrchestrationVersioning(this.worker.workerOptions.Versioning, request.Version, out bool versioningFailed);
778+
if (!versioningFailed)
779+
{
780+
try
781+
{
782+
await using AsyncServiceScope scope = this.worker.services.CreateAsyncScope();
783+
if (this.worker.Factory.TryCreateActivity(name, scope.ServiceProvider, out ITaskActivity? activity))
784+
{
785+
// Both the factory invocation and the RunAsync could involve user code and need to be handled as
786+
// part of try/catch.
787+
TaskActivity shim = this.shimFactory.CreateActivity(name, activity);
788+
output = await shim.RunAsync(innerContext, request.Input);
789+
}
790+
else
791+
{
792+
failureDetails = new P.TaskFailureDetails
793+
{
794+
ErrorType = "ActivityTaskNotFound",
795+
ErrorMessage = $"No activity task named '{name}' was found.",
796+
IsNonRetriable = true,
797+
};
798+
}
799+
}
800+
catch (Exception applicationException)
801+
{
802+
failureDetails = applicationException.ToTaskFailureDetails(this.exceptionPropertiesProvider);
803+
}
804+
}
805+
else
806+
{
807+
if (this.worker.workerOptions.Versioning?.FailureStrategy == DurableTaskWorkerOptions.VersionFailureStrategy.Reject)
808+
{
809+
this.Logger.AbandoningActivityWorkItem(instance.InstanceId, request.Name, request.TaskId, completionToken);
810+
await this.client.AbandonTaskActivityWorkItemAsync(
811+
new P.AbandonActivityTaskRequest
812+
{
813+
CompletionToken = completionToken,
814+
},
815+
cancellationToken: cancellation);
816+
}
817+
818+
return;
819+
}
820+
777821
try
778822
{
779823
await using AsyncServiceScope scope = this.worker.services.CreateAsyncScope();

test/Grpc.IntegrationTests/GrpcSidecar/Grpc/ProtobufUtils.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ public static string Base64Encode(IMessage message)
359359
failureDetails.StackTrace,
360360
GetFailureDetails(failureDetails.InnerFailure),
361361
failureDetails.IsNonRetriable,
362-
ConvertProperties(failureDetails.Properties));
362+
ConvertMapToDictionary(failureDetails.Properties));
363363
}
364364

365365
internal static Proto.TaskFailureDetails? GetFailureDetails(FailureDetails? failureDetails)
@@ -368,7 +368,7 @@ public static string Base64Encode(IMessage message)
368368
{
369369
return null;
370370
}
371-
371+
372372
var taskFailureDetails = new Proto.TaskFailureDetails
373373
{
374374
ErrorType = failureDetails.ErrorType,
@@ -454,7 +454,7 @@ internal static Proto.PurgeInstancesResponse CreatePurgeInstancesResponse(PurgeR
454454
}
455455

456456
/// <summary>
457-
/// Converts a Dictionary<string, object?> into a MapField<string, Value>.
457+
/// Converts a IDictionary<string, object?> into a MapField<string, Value>.
458458
/// Supports nested dictionaries and lists.
459459
/// </summary>
460460
public static MapField<string, Value> ConvertDictionaryToMapField(IDictionary<string, object?> dict)
@@ -470,15 +470,15 @@ public static MapField<string, Value> ConvertDictionaryToMapField(IDictionary<st
470470
}
471471

472472
/// <summary>
473-
///
473+
/// Converts a MapField<string, Value> into a IDictionary<string, object?>.
474474
/// </summary>
475475
/// <param name="properties"></param>
476476
/// <returns></returns>
477-
public static IDictionary<string, object> ConvertProperties(MapField<string, Value> properties)
477+
public static IDictionary<string, object?> ConvertMapToDictionary(MapField<string, Value> properties)
478478
{
479479
return properties.ToDictionary(
480480
kvp => kvp.Key,
481-
kvp => ConvertValue(kvp.Value)
481+
kvp => ConvertValueToObject(kvp.Value)
482482
);
483483
}
484484

@@ -487,7 +487,7 @@ public static IDictionary<string, object> ConvertProperties(MapField<string, Val
487487
/// </summary>
488488
/// <param name="obj">The object to convert.</param>
489489
/// <returns>The converted protobuf Value.</returns>
490-
private static Value ConvertObjectToValue(object? obj)
490+
static Value ConvertObjectToValue(object? obj)
491491
{
492492
return obj switch
493493
{
@@ -510,7 +510,7 @@ private static Value ConvertObjectToValue(object? obj)
510510
};
511511
}
512512

513-
private static object ConvertValue(Value value)
513+
static object ConvertValueToObject(Value value)
514514
{
515515
switch (value.KindCase)
516516
{
@@ -521,9 +521,9 @@ private static object ConvertValue(Value value)
521521
case Value.KindOneofCase.BoolValue:
522522
return value.BoolValue;
523523
case Value.KindOneofCase.StructValue:
524-
return value.StructValue.Fields.ToDictionary(f => f.Key, f => ConvertValue(f.Value));
524+
return value.StructValue.Fields.ToDictionary(f => f.Key, f => ConvertValueToObject(f.Value));
525525
case Value.KindOneofCase.ListValue:
526-
return value.ListValue.Values.Select(ConvertValue).ToList();
526+
return value.ListValue.Values.Select(ConvertValueToObject).ToList();
527527
case Value.KindOneofCase.NullValue:
528528
return null!;
529529
default:

test/Grpc.IntegrationTests/OrchestrationErrorHandling.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -633,15 +633,15 @@ static Exception MakeException(Type exceptionType, string message)
633633
}
634634

635635
/// <summary>
636-
/// Tests that custom exception properties are included in FailureDetails when using a custom IExceptionPropertiesProvider.
636+
/// Tests that exception properties are included in FailureDetails when using a custom IExceptionPropertiesProvider.
637637
/// </summary>
638638
[Fact]
639639
public async Task CustomExceptionPropertiesInFailureDetails()
640640
{
641641
TaskName orchestratorName = "OrchestrationWithCustomException";
642642
TaskName activityName = "BusinessActivity";
643643

644-
// Use local function definitions
644+
// Register activity functions that will throw a exception.
645645
async Task MyOrchestrationImpl(TaskOrchestrationContext ctx) =>
646646
await ctx.CallActivityAsync(activityName);
647647

0 commit comments

Comments
 (0)