Skip to content

Commit 7c4b3ae

Browse files
committed
Merge upstream/main into signal_with_start
Resolved conflicts: - Added Generic import to support Generic[C] type parameter - Removed unused TYPE_CHECKING import and empty block - Removed client() method from WorkflowContext (removed in upstream) - Removed test_workflow_engine_integration.py as upstream reorganized tests - Adopted upstream's frozen=True for WorkflowInfo
2 parents d42e22e + 890fe83 commit 7c4b3ae

22 files changed

+1297
-1385
lines changed

cadence/_internal/workflow/context.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,34 @@
1+
from contextlib import contextmanager
12
from datetime import timedelta
23
from math import ceil
3-
from typing import Optional, Any, Unpack, Type, cast
4+
from typing import Iterator, Optional, Any, Unpack, Type, cast
45

56
from cadence._internal.workflow.statemachine.decision_manager import DecisionManager
67
from cadence._internal.workflow.decisions_helper import DecisionsHelper
78
from cadence.api.v1.common_pb2 import ActivityType
89
from cadence.api.v1.decision_pb2 import ScheduleActivityTaskDecisionAttributes
910
from cadence.api.v1.tasklist_pb2 import TaskList, TaskListKind
10-
from cadence.client import Client
1111
from cadence.data_converter import DataConverter
1212
from cadence.workflow import WorkflowContext, WorkflowInfo, ResultType, ActivityOptions
1313

1414

1515
class Context(WorkflowContext):
1616
def __init__(
1717
self,
18-
client: Client,
1918
info: WorkflowInfo,
20-
decision_helper: DecisionsHelper,
2119
decision_manager: DecisionManager,
2220
):
23-
self._client = client
2421
self._info = info
2522
self._replay_mode = True
2623
self._replay_current_time_milliseconds: Optional[int] = None
27-
self._decision_helper = decision_helper
24+
self._decision_helper = DecisionsHelper()
2825
self._decision_manager = decision_manager
2926

3027
def info(self) -> WorkflowInfo:
3128
return self._info
3229

33-
def client(self) -> Client:
34-
return self._client
35-
3630
def data_converter(self) -> DataConverter:
37-
return self._client.data_converter
31+
return self.info().data_converter
3832

3933
async def execute_activity(
4034
self,
@@ -80,7 +74,7 @@ async def execute_activity(
8074
schedule_attributes = ScheduleActivityTaskDecisionAttributes(
8175
activity_id=activity_id,
8276
activity_type=ActivityType(name=activity),
83-
domain=self._client.domain,
77+
domain=self.info().workflow_domain,
8478
task_list=TaskList(kind=TaskListKind.TASK_LIST_KIND_NORMAL, name=task_list),
8579
input=activity_input,
8680
schedule_to_close_timeout=_round_to_nearest_second(schedule_to_close),
@@ -116,6 +110,12 @@ def get_replay_current_time_milliseconds(self) -> Optional[int]:
116110
"""Get the current replay time in milliseconds."""
117111
return self._replay_current_time_milliseconds
118112

113+
@contextmanager
114+
def _activate(self) -> Iterator["Context"]:
115+
token = WorkflowContext._var.set(self)
116+
yield self
117+
WorkflowContext._var.reset(token)
118+
119119

120120
def _round_to_nearest_second(delta: timedelta) -> timedelta:
121121
return timedelta(seconds=ceil(delta.total_seconds()))

0 commit comments

Comments
 (0)