|
62 | 62 | import temporalio.service |
63 | 63 | import temporalio.workflow |
64 | 64 | from temporalio.activity import ActivityCancellationDetails |
65 | | -from temporalio.converter import WorkflowSerializationContext |
| 65 | +from temporalio.converter import ( |
| 66 | + ActivitySerializationContext, |
| 67 | + DataConverter, |
| 68 | + WorkflowSerializationContext, |
| 69 | +) |
66 | 70 | from temporalio.service import ( |
67 | 71 | HttpConnectProxyConfig, |
68 | 72 | KeepAliveConfig, |
@@ -6391,10 +6395,11 @@ async def _start_workflow_update_with_start( |
6391 | 6395 | async def heartbeat_async_activity( |
6392 | 6396 | self, input: HeartbeatAsyncActivityInput |
6393 | 6397 | ) -> None: |
| 6398 | + data_converter = self._async_activity_data_converter(input.id_or_token) |
6394 | 6399 | details = ( |
6395 | 6400 | None |
6396 | 6401 | if not input.details |
6397 | | - else await self._client.data_converter.encode_wrapper(input.details) |
| 6402 | + else await data_converter.encode_wrapper(input.details) |
6398 | 6403 | ) |
6399 | 6404 | if isinstance(input.id_or_token, AsyncActivityIDReference): |
6400 | 6405 | resp_by_id = await self._client.workflow_service.record_activity_task_heartbeat_by_id( |
@@ -6445,10 +6450,11 @@ async def heartbeat_async_activity( |
6445 | 6450 | ) |
6446 | 6451 |
|
6447 | 6452 | async def complete_async_activity(self, input: CompleteAsyncActivityInput) -> None: |
| 6453 | + data_converter = self._async_activity_data_converter(input.id_or_token) |
6448 | 6454 | result = ( |
6449 | 6455 | None |
6450 | 6456 | if input.result is temporalio.common._arg_unset |
6451 | | - else await self._client.data_converter.encode_wrapper([input.result]) |
| 6457 | + else await data_converter.encode_wrapper([input.result]) |
6452 | 6458 | ) |
6453 | 6459 | if isinstance(input.id_or_token, AsyncActivityIDReference): |
6454 | 6460 | await self._client.workflow_service.respond_activity_task_completed_by_id( |
@@ -6478,14 +6484,14 @@ async def complete_async_activity(self, input: CompleteAsyncActivityInput) -> No |
6478 | 6484 | ) |
6479 | 6485 |
|
6480 | 6486 | async def fail_async_activity(self, input: FailAsyncActivityInput) -> None: |
| 6487 | + data_converter = self._async_activity_data_converter(input.id_or_token) |
| 6488 | + |
6481 | 6489 | failure = temporalio.api.failure.v1.Failure() |
6482 | | - await self._client.data_converter.encode_failure(input.error, failure) |
| 6490 | + await data_converter.encode_failure(input.error, failure) |
6483 | 6491 | last_heartbeat_details = ( |
6484 | 6492 | None |
6485 | 6493 | if not input.last_heartbeat_details |
6486 | | - else await self._client.data_converter.encode_wrapper( |
6487 | | - input.last_heartbeat_details |
6488 | | - ) |
| 6494 | + else await data_converter.encode_wrapper(input.last_heartbeat_details) |
6489 | 6495 | ) |
6490 | 6496 | if isinstance(input.id_or_token, AsyncActivityIDReference): |
6491 | 6497 | await self._client.workflow_service.respond_activity_task_failed_by_id( |
@@ -6519,10 +6525,11 @@ async def fail_async_activity(self, input: FailAsyncActivityInput) -> None: |
6519 | 6525 | async def report_cancellation_async_activity( |
6520 | 6526 | self, input: ReportCancellationAsyncActivityInput |
6521 | 6527 | ) -> None: |
| 6528 | + data_converter = self._async_activity_data_converter(input.id_or_token) |
6522 | 6529 | details = ( |
6523 | 6530 | None |
6524 | 6531 | if not input.details |
6525 | | - else await self._client.data_converter.encode_wrapper(input.details) |
| 6532 | + else await data_converter.encode_wrapper(input.details) |
6526 | 6533 | ) |
6527 | 6534 | if isinstance(input.id_or_token, AsyncActivityIDReference): |
6528 | 6535 | await self._client.workflow_service.respond_activity_task_canceled_by_id( |
@@ -6551,6 +6558,23 @@ async def report_cancellation_async_activity( |
6551 | 6558 | timeout=input.rpc_timeout, |
6552 | 6559 | ) |
6553 | 6560 |
|
| 6561 | + def _async_activity_data_converter( |
| 6562 | + self, id_or_token: Union[AsyncActivityIDReference, bytes] |
| 6563 | + ) -> DataConverter: |
| 6564 | + context = ActivitySerializationContext( |
| 6565 | + namespace=self._client.namespace, |
| 6566 | + workflow_id=( |
| 6567 | + id_or_token.workflow_id |
| 6568 | + if isinstance(id_or_token, AsyncActivityIDReference) |
| 6569 | + else "" |
| 6570 | + ), |
| 6571 | + workflow_type="", |
| 6572 | + activity_type="", |
| 6573 | + activity_task_queue="", |
| 6574 | + is_local=False, |
| 6575 | + ) |
| 6576 | + return self._client.data_converter._with_context(context) |
| 6577 | + |
6554 | 6578 | ### Schedule calls |
6555 | 6579 |
|
6556 | 6580 | async def create_schedule(self, input: CreateScheduleInput) -> ScheduleHandle: |
|
0 commit comments