@@ -26,13 +26,32 @@ def handle(self, context_string: str):
26
26
activity_context = IFunctionContext (df = self .durable_context )
27
27
28
28
self .generator = self .fn (activity_context )
29
-
29
+ suspended = False
30
30
try :
31
- starting_state = self ._generate_next (None )
31
+ generation_state = self ._generate_next (None )
32
+
33
+ while not suspended :
34
+ self ._add_to_actions (generation_state )
35
+
36
+ if should_suspend (generation_state ):
37
+ orchestration_state = OrchestratorState (
38
+ isDone = False ,
39
+ output = None ,
40
+ actions = self .durable_context .actions ,
41
+ customStatus = self .customStatus )
42
+ suspended = True
43
+ continue
44
+
45
+ if (isinstance (generation_state , Task )
46
+ or isinstance (generation_state , TaskSet )) and (
47
+ generation_state .isFaulted ):
48
+ generation_state = self .generator .throw (generation_state .exception )
49
+ continue
50
+
51
+ self ._reset_timestamp ()
52
+ generation_state = self ._generate_next (generation_state )
32
53
33
- orchestration_state = self ._get_orchestration_state (starting_state )
34
54
except StopIteration as sie :
35
- logging .warning (f"!!!Generator Termination StopIteration { sie } " )
36
55
orchestration_state = OrchestratorState (
37
56
isDone = True ,
38
57
output = sie .value ,
@@ -57,30 +76,6 @@ def _generate_next(self, partial_result):
57
76
gen_result = self .generator .send (None )
58
77
return gen_result
59
78
60
- def _get_orchestration_state (self , generation_state ):
61
- logging .warning (f"!!!actions { self .durable_context .actions } " )
62
- logging .warning (f"!!!Generator Execution { generation_state } " )
63
-
64
- self ._add_to_actions (generation_state )
65
-
66
- if should_suspend (generation_state ):
67
- logging .warning (f"!!!Generator Suspended" )
68
- return OrchestratorState (
69
- isDone = False ,
70
- output = None ,
71
- actions = self .durable_context .actions ,
72
- customStatus = self .customStatus )
73
-
74
- if (isinstance (generation_state , Task )
75
- or isinstance (generation_state , TaskSet )) and (
76
- generation_state .isFaulted ):
77
- return self ._get_orchestration_state (self .generator .throw (generation_state .exception ))
78
-
79
- self ._reset_timestamp ()
80
-
81
- logging .warning (f"!!!Generator Execution { generation_state } " )
82
- return self ._get_orchestration_state (self ._generate_next (generation_state ))
83
-
84
79
def _add_to_actions (self , generation_state ):
85
80
if (isinstance (generation_state , Task )
86
81
and hasattr (generation_state , "action" )):
0 commit comments