Skip to content

Commit 609dd3e

Browse files
authored
Serialize "innerTasks" only at the end of the orchestrator invocation (#369)
1 parent 34472ac commit 609dd3e

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

azure/durable_functions/models/actions/CompoundAction.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ class CompoundAction(Action):
1212
Provides the information needed by the durable extension to be able to invoke WhenAll tasks.
1313
"""
1414

15-
def __init__(self, compoundTasks: List[Action]):
16-
self.compound_actions = list(map(lambda x: x.to_json(), compoundTasks))
15+
def __init__(self, compound_tasks: List[Action]):
16+
self.compound_tasks = compound_tasks
1717

1818
@property
1919
@abstractmethod
@@ -31,5 +31,5 @@ def to_json(self) -> Dict[str, Union[str, int]]:
3131
"""
3232
json_dict: Dict[str, Union[str, int]] = {}
3333
add_attrib(json_dict, self, 'action_type', 'actionType')
34-
add_attrib(json_dict, self, 'compound_actions', 'compoundActions')
34+
json_dict['compoundActions'] = list(map(lambda x: x.to_json(), self.compound_tasks))
3535
return json_dict

tests/orchestrator/test_create_timer.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from azure.durable_functions.models.ReplaySchema import ReplaySchema
2+
from azure.durable_functions.models.actions.WhenAnyAction import WhenAnyAction
23
from tests.test_utils.ContextBuilder import ContextBuilder
34
from .orchestrator_test_utils \
45
import get_orchestration_state_result, assert_orchestration_state_equals, assert_valid_schema
@@ -9,7 +10,7 @@
910

1011

1112
def base_expected_state(output=None, replay_schema: ReplaySchema = ReplaySchema.V1) -> OrchestratorState:
12-
return OrchestratorState(is_done=False, actions=[], output=output, replay_schema=replay_schema.value)
13+
return OrchestratorState(is_done=False, actions=[], output=output, replay_schema=replay_schema)
1314

1415
def add_timer_fired_events(context_builder: ContextBuilder, id_: int, timestamp: str):
1516
fire_at: str = context_builder.add_timer_created_event(id_, timestamp)
@@ -99,4 +100,28 @@ def test_timers_can_be_cancelled():
99100
expected = expected_state.to_json()
100101

101102
assert_orchestration_state_equals(expected, result)
102-
assert result["actions"][0][1]["isCanceled"]
103+
assert result["actions"][0][1]["isCanceled"]
104+
105+
def test_timers_can_be_cancelled_replayV2():
106+
107+
context_builder = ContextBuilder("test_timers_can_be_cancelled", replay_schema=ReplaySchema.V2)
108+
fire_at1 = context_builder.current_datetime + timedelta(minutes=5)
109+
fire_at2 = context_builder.current_datetime + timedelta(minutes=10)
110+
add_timer_fired_events(context_builder, 0, str(fire_at1))
111+
add_timer_fired_events(context_builder, 1, str(fire_at2))
112+
113+
result = get_orchestration_state_result(
114+
context_builder, generator_function_timer_can_be_cancelled)
115+
116+
expected_state = base_expected_state(output='Done!', replay_schema=ReplaySchema.V2)
117+
expected_state._actions = [
118+
[WhenAnyAction(
119+
[CreateTimerAction(fire_at=fire_at1), CreateTimerAction(fire_at=fire_at2, is_cancelled=True)]
120+
)]
121+
]
122+
123+
expected_state._is_done = True
124+
expected = expected_state.to_json()
125+
126+
assert_orchestration_state_equals(expected, result)
127+
assert result["actions"][0][0]['compoundActions'][1]["isCanceled"]

0 commit comments

Comments
 (0)