Skip to content

Commit 7e77ba2

Browse files
committed
Put while loop back in, with better readability
1 parent 56f457d commit 7e77ba2

File tree

1 file changed

+23
-28
lines changed

1 file changed

+23
-28
lines changed

azure/durable_functions/orchestrator.py

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,32 @@ def handle(self, context_string: str):
2626
activity_context = IFunctionContext(df=self.durable_context)
2727

2828
self.generator = self.fn(activity_context)
29-
29+
suspended = False
3030
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)
3253

33-
orchestration_state = self._get_orchestration_state(starting_state)
3454
except StopIteration as sie:
35-
logging.warning(f"!!!Generator Termination StopIteration {sie}")
3655
orchestration_state = OrchestratorState(
3756
isDone=True,
3857
output=sie.value,
@@ -57,30 +76,6 @@ def _generate_next(self, partial_result):
5776
gen_result = self.generator.send(None)
5877
return gen_result
5978

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-
8479
def _add_to_actions(self, generation_state):
8580
if (isinstance(generation_state, Task)
8681
and hasattr(generation_state, "action")):

0 commit comments

Comments
 (0)