@@ -20,7 +20,8 @@ public void StopAndInitiateDurableTaskOrReplay(
2020 OrchestrationContext context ,
2121 bool noWait ,
2222 Action < object > output ,
23- Action < string > onFailure )
23+ Action < string > onFailure ,
24+ RetryOptions retryOptions = null )
2425 {
2526 context . OrchestrationActionCollector . Add ( task . CreateOrchestrationAction ( ) ) ;
2627
@@ -30,6 +31,8 @@ public void StopAndInitiateDurableTaskOrReplay(
3031 }
3132 else
3233 {
34+ context . OrchestrationActionCollector . NextBatch ( ) ;
35+
3336 var scheduledHistoryEvent = task . GetScheduledHistoryEvent ( context ) ;
3437 var completedHistoryEvent = task . GetCompletedHistoryEvent ( context , scheduledHistoryEvent ) ;
3538
@@ -56,7 +59,32 @@ public void StopAndInitiateDurableTaskOrReplay(
5659 break ;
5760
5861 case HistoryEventType . TaskFailed :
59- onFailure ( completedHistoryEvent . Reason ) ;
62+ if ( retryOptions == null )
63+ {
64+ onFailure ( completedHistoryEvent . Reason ) ;
65+ }
66+ else
67+ {
68+ // Reset IsProcessed, let RetryProcessor handle these events instead.
69+ scheduledHistoryEvent . IsProcessed = false ;
70+ completedHistoryEvent . IsProcessed = false ;
71+
72+ var shouldContinueProcessing =
73+ RetryProcessor . Process (
74+ context . History ,
75+ scheduledHistoryEvent ,
76+ retryOptions . MaxNumberOfAttempts ,
77+ onSuccess :
78+ result => {
79+ output ( TypeExtensions . ConvertFromJson ( result ) ) ;
80+ } ,
81+ onFailure ) ;
82+
83+ if ( shouldContinueProcessing )
84+ {
85+ InitiateAndWaitForStop ( context ) ;
86+ }
87+ }
6088 break ;
6189 }
6290 }
@@ -73,6 +101,8 @@ public void WaitAll(
73101 OrchestrationContext context ,
74102 Action < object > output )
75103 {
104+ context . OrchestrationActionCollector . NextBatch ( ) ;
105+
76106 var completedEvents = new List < HistoryEvent > ( ) ;
77107 foreach ( var task in tasksToWaitFor )
78108 {
@@ -118,6 +148,8 @@ public void WaitAny(
118148 OrchestrationContext context ,
119149 Action < object > output )
120150 {
151+ context . OrchestrationActionCollector . NextBatch ( ) ;
152+
121153 var completedTasks = new List < DurableTask > ( ) ;
122154 DurableTask firstCompletedTask = null ;
123155 int firstCompletedHistoryEventIndex = - 1 ;
0 commit comments