|
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,6 +6395,7 @@ async def _start_workflow_update_with_start( |
6391 | 6395 | async def heartbeat_async_activity( |
6392 | 6396 | self, input: HeartbeatAsyncActivityInput |
6393 | 6397 | ) -> None: |
| 6398 | + # TODO |
6394 | 6399 | details = ( |
6395 | 6400 | None |
6396 | 6401 | if not input.details |
@@ -6444,11 +6449,29 @@ async def heartbeat_async_activity( |
6444 | 6449 | ) |
6445 | 6450 | ) |
6446 | 6451 |
|
| 6452 | + def _async_activity_data_converter( |
| 6453 | + self, id_or_token: Union[AsyncActivityIDReference, bytes] |
| 6454 | + ) -> DataConverter: |
| 6455 | + context = ActivitySerializationContext( |
| 6456 | + namespace=self._client.namespace, |
| 6457 | + workflow_id=( |
| 6458 | + id_or_token.workflow_id |
| 6459 | + if isinstance(id_or_token, AsyncActivityIDReference) |
| 6460 | + else "" |
| 6461 | + ), |
| 6462 | + workflow_type="", |
| 6463 | + activity_type="", |
| 6464 | + activity_task_queue="", |
| 6465 | + is_local=False, |
| 6466 | + ) |
| 6467 | + return self._client.data_converter._with_context(context) |
| 6468 | + |
6447 | 6469 | async def complete_async_activity(self, input: CompleteAsyncActivityInput) -> None: |
| 6470 | + data_converter = self._async_activity_data_converter(input.id_or_token) |
6448 | 6471 | result = ( |
6449 | 6472 | None |
6450 | 6473 | if input.result is temporalio.common._arg_unset |
6451 | | - else await self._client.data_converter.encode_wrapper([input.result]) |
| 6474 | + else await data_converter.encode_wrapper([input.result]) |
6452 | 6475 | ) |
6453 | 6476 | if isinstance(input.id_or_token, AsyncActivityIDReference): |
6454 | 6477 | await self._client.workflow_service.respond_activity_task_completed_by_id( |
@@ -6478,14 +6501,14 @@ async def complete_async_activity(self, input: CompleteAsyncActivityInput) -> No |
6478 | 6501 | ) |
6479 | 6502 |
|
6480 | 6503 | async def fail_async_activity(self, input: FailAsyncActivityInput) -> None: |
| 6504 | + data_converter = self._async_activity_data_converter(input.id_or_token) |
| 6505 | + |
6481 | 6506 | failure = temporalio.api.failure.v1.Failure() |
6482 | | - await self._client.data_converter.encode_failure(input.error, failure) |
| 6507 | + await data_converter.encode_failure(input.error, failure) |
6483 | 6508 | last_heartbeat_details = ( |
6484 | 6509 | None |
6485 | 6510 | if not input.last_heartbeat_details |
6486 | | - else await self._client.data_converter.encode_wrapper( |
6487 | | - input.last_heartbeat_details |
6488 | | - ) |
| 6511 | + else await data_converter.encode_wrapper(input.last_heartbeat_details) |
6489 | 6512 | ) |
6490 | 6513 | if isinstance(input.id_or_token, AsyncActivityIDReference): |
6491 | 6514 | await self._client.workflow_service.respond_activity_task_failed_by_id( |
@@ -6519,10 +6542,11 @@ async def fail_async_activity(self, input: FailAsyncActivityInput) -> None: |
6519 | 6542 | async def report_cancellation_async_activity( |
6520 | 6543 | self, input: ReportCancellationAsyncActivityInput |
6521 | 6544 | ) -> None: |
| 6545 | + data_converter = self._async_activity_data_converter(input.id_or_token) |
6522 | 6546 | details = ( |
6523 | 6547 | None |
6524 | 6548 | if not input.details |
6525 | | - else await self._client.data_converter.encode_wrapper(input.details) |
| 6549 | + else await data_converter.encode_wrapper(input.details) |
6526 | 6550 | ) |
6527 | 6551 | if isinstance(input.id_or_token, AsyncActivityIDReference): |
6528 | 6552 | await self._client.workflow_service.respond_activity_task_canceled_by_id( |
|
0 commit comments