Skip to content

Commit 95e794f

Browse files
authored
Detect sub-task completion in constructor (#391)
1 parent aab7bc1 commit 95e794f

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

azure/durable_functions/models/Task.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,11 @@ def __init__(self, tasks: List[TaskBase], compound_action_constructor=None):
171171
if len(self.children) == 0:
172172
self.state = TaskState.SUCCEEDED
173173

174+
# Sub-tasks may have already completed, so we process them
175+
for child in self.children:
176+
if not(child.state is TaskState.RUNNING):
177+
self.handle_completion(child)
178+
174179
def handle_completion(self, child: TaskBase):
175180
"""Manage sub-task completion events.
176181

tests/orchestrator/test_sequential_orchestrator.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ def generator_function(context):
2424

2525
return outputs
2626

27+
def generator_function_multi_yield_when_all(context):
28+
outputs = []
29+
30+
task1 = context.call_activity("Hello", "Tokyo")
31+
yield context.task_all([task1])
32+
result = yield context.task_all([task1])
33+
34+
return result
35+
2736
def generator_function_is_replaying(context):
2837
outputs = []
2938

@@ -297,6 +306,22 @@ def test_tokyo_and_seattle_and_london_state():
297306
assert_valid_schema(result)
298307
assert_orchestration_state_equals(expected, result)
299308

309+
def test_multi_when_all_yield():
310+
context_builder = ContextBuilder('test_simple_function')
311+
add_hello_completed_events(context_builder, 0, "\"Hello Tokyo!\"")
312+
313+
result = get_orchestration_state_result(
314+
context_builder, generator_function_multi_yield_when_all)
315+
316+
expected_state = base_expected_state(
317+
['Hello Tokyo!'])
318+
add_hello_action(expected_state, 'Tokyo')
319+
expected_state._is_done = True
320+
expected = expected_state.to_json()
321+
322+
assert_valid_schema(result)
323+
assert_orchestration_state_equals(expected, result)
324+
300325
def test_sequential_is_replaying():
301326
context_builder = ContextBuilder('test_simple_function', is_replaying=True)
302327
add_hello_completed_events(context_builder, 0, "\"Hello Tokyo!\"", True)

0 commit comments

Comments
 (0)