@@ -759,37 +759,56 @@ async Task OnRunActivityAsync(P.ActivityRequest request, string completionToken,
759759
760760 OrchestrationInstance instance = request . OrchestrationInstance . ToCore ( ) ;
761761 string rawInput = request . Input ;
762-
763762 int inputSize = rawInput != null ? Encoding . UTF8 . GetByteCount ( rawInput ) : 0 ;
764763 this . Logger . ReceivedActivityRequest ( request . Name , request . TaskId , instance . InstanceId , inputSize ) ;
765764
765+ P . TaskFailureDetails ? failureDetails = null ;
766766 TaskContext innerContext = new ( instance ) ;
767767 TaskName name = new ( request . Name ) ;
768768 string ? output = null ;
769- P . TaskFailureDetails ? failureDetails = null ;
770- try
769+
770+ failureDetails = EvaluateOrchestrationVersioning ( this . worker . workerOptions . Versioning , request . Version , out bool versioningFailed ) ;
771+ if ( ! versioningFailed )
771772 {
772- await using AsyncServiceScope scope = this . worker . services . CreateAsyncScope ( ) ;
773- if ( this . worker . Factory . TryCreateActivity ( name , scope . ServiceProvider , out ITaskActivity ? activity ) )
773+ try
774774 {
775- // Both the factory invocation and the RunAsync could involve user code and need to be handled as
776- // part of try/catch.
777- TaskActivity shim = this . shimFactory . CreateActivity ( name , activity ) ;
778- output = await shim . RunAsync ( innerContext , request . Input ) ;
775+ await using AsyncServiceScope scope = this . worker . services . CreateAsyncScope ( ) ;
776+ if ( this . worker . Factory . TryCreateActivity ( name , scope . ServiceProvider , out ITaskActivity ? activity ) )
777+ {
778+ // Both the factory invocation and the RunAsync could involve user code and need to be handled as
779+ // part of try/catch.
780+ TaskActivity shim = this . shimFactory . CreateActivity ( name , activity ) ;
781+ output = await shim . RunAsync ( innerContext , request . Input ) ;
782+ }
783+ else
784+ {
785+ failureDetails = new P . TaskFailureDetails
786+ {
787+ ErrorType = "ActivityTaskNotFound" ,
788+ ErrorMessage = $ "No activity task named '{ name } ' was found.",
789+ IsNonRetriable = true ,
790+ } ;
791+ }
779792 }
780- else
793+ catch ( Exception applicationException )
781794 {
782- failureDetails = new P . TaskFailureDetails
783- {
784- ErrorType = "ActivityTaskNotFound" ,
785- ErrorMessage = $ "No activity task named '{ name } ' was found.",
786- IsNonRetriable = true ,
787- } ;
795+ failureDetails = applicationException . ToTaskFailureDetails ( ) ;
788796 }
789797 }
790- catch ( Exception applicationException )
798+ else
791799 {
792- failureDetails = applicationException . ToTaskFailureDetails ( ) ;
800+ if ( this . worker . workerOptions . Versioning ? . FailureStrategy == DurableTaskWorkerOptions . VersionFailureStrategy . Reject )
801+ {
802+ this . Logger . AbandoningActivityWorkItem ( instance . InstanceId , request . Name , request . TaskId , completionToken ) ;
803+ await this . client . AbandonTaskActivityWorkItemAsync (
804+ new P . AbandonActivityTaskRequest
805+ {
806+ CompletionToken = completionToken ,
807+ } ,
808+ cancellationToken : cancellation ) ;
809+ }
810+
811+ return ;
793812 }
794813
795814 int outputSizeInBytes = 0 ;
0 commit comments