Skip to content

Commit 44f0c42

Browse files
authored
Added retry policy to activity info (#1055)
1 parent 30a6b8d commit 44f0c42

File tree

5 files changed

+29
-6
lines changed

5 files changed

+29
-6
lines changed

temporalio/activity.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,13 @@ class Info:
124124
workflow_run_id: str
125125
workflow_type: str
126126
priority: temporalio.common.Priority
127+
retry_policy: Optional[temporalio.common.RetryPolicy]
128+
"""The retry policy of this activity.
129+
130+
Note that the server may have set a different policy than the one provided when scheduling the activity.
131+
If the value is None, it means the server didn't send information about retry policy (e.g. due to old server
132+
version), but it may still be defined server-side."""
133+
127134
# TODO(cretz): Consider putting identity on here for "worker_id" for logger?
128135

129136
def _logger_details(self) -> Mapping[str, Any]:

temporalio/testing/_activity.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
workflow_run_id="test-run",
4242
workflow_type="test",
4343
priority=temporalio.common.Priority.default,
44+
retry_policy=None,
4445
)
4546

4647

temporalio/worker/_activity.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,9 @@ async def _execute_activity(
558558
workflow_run_id=start.workflow_execution.run_id,
559559
workflow_type=start.workflow_type,
560560
priority=temporalio.common.Priority._from_proto(start.priority),
561+
retry_policy=temporalio.common.RetryPolicy.from_proto(start.retry_policy)
562+
if start.HasField("retry_policy")
563+
else None,
561564
)
562565

563566
if self._encode_headers and self._data_converter.payload_codec is not None:

tests/helpers/worker.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,9 @@ def signal_handler(arg: Optional[Any] = None) -> None:
140140
opt = action.execute_activity
141141
config = workflow.ActivityConfig(
142142
task_queue=opt.task_queue,
143-
retry_policy=RetryPolicy(
144-
initial_interval=timedelta(milliseconds=1),
145-
backoff_coefficient=1.01,
146-
maximum_interval=timedelta(milliseconds=2),
147-
maximum_attempts=opt.retry_max_attempts or 1,
148-
non_retryable_error_types=opt.non_retryable_error_types or [],
143+
retry_policy=kitchen_sink_retry_policy(
144+
maximum_attempts=opt.retry_max_attempts,
145+
non_retryable_error_types=opt.non_retryable_error_types,
149146
),
150147
)
151148
if opt.schedule_to_close_timeout_ms:
@@ -207,6 +204,19 @@ async def run_activity(index: int) -> None:
207204
return False, None
208205

209206

207+
def kitchen_sink_retry_policy(
208+
maximum_attempts: Optional[int] = None,
209+
non_retryable_error_types: Optional[Sequence[str]] = None,
210+
) -> RetryPolicy:
211+
return RetryPolicy(
212+
initial_interval=timedelta(milliseconds=1),
213+
backoff_coefficient=1.01,
214+
maximum_interval=timedelta(milliseconds=2),
215+
maximum_attempts=maximum_attempts or 1,
216+
non_retryable_error_types=non_retryable_error_types,
217+
)
218+
219+
210220
async def cancel_after(task: asyncio.Task, after: float) -> None:
211221
await asyncio.sleep(after)
212222
task.cancel()

tests/worker/test_activity.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
KSAction,
4848
KSExecuteActivityAction,
4949
KSWorkflowParams,
50+
kitchen_sink_retry_policy,
5051
)
5152

5253
# Passing through because Python 3.9 has an import bug at
@@ -186,6 +187,7 @@ async def capture_info() -> None:
186187
assert info.workflow_namespace == client.namespace
187188
assert info.workflow_run_id == result.handle.first_execution_run_id
188189
assert info.workflow_type == "kitchen_sink"
190+
assert info.retry_policy == kitchen_sink_retry_policy()
189191

190192

191193
async def test_sync_activity_thread(client: Client, worker: ExternalWorker):

0 commit comments

Comments
 (0)