|
64 | 64 | import temporalio.workflow
|
65 | 65 | from temporalio.service import __version__
|
66 | 66 |
|
| 67 | +from ..api.failure.v1.message_pb2 import Failure |
67 | 68 | from ._interceptor import (
|
68 | 69 | ContinueAsNewInput,
|
69 | 70 | ExecuteWorkflowInput,
|
@@ -143,6 +144,8 @@ class WorkflowInstanceDetails:
|
143 | 144 | extern_functions: Mapping[str, Callable]
|
144 | 145 | disable_eager_activity_execution: bool
|
145 | 146 | worker_level_failure_exception_types: Sequence[Type[BaseException]]
|
| 147 | + last_completion_result: temporalio.api.common.v1.Payloads |
| 148 | + last_failure: Optional[Failure] |
146 | 149 |
|
147 | 150 |
|
148 | 151 | class WorkflowInstance(ABC):
|
@@ -320,6 +323,9 @@ def __init__(self, det: WorkflowInstanceDetails) -> None:
|
320 | 323 | # metadata query
|
321 | 324 | self._current_details = ""
|
322 | 325 |
|
| 326 | + self._last_completion_result = det.last_completion_result |
| 327 | + self._last_failure = det.last_failure |
| 328 | + |
323 | 329 | # The versioning behavior of this workflow, as established by annotation or by the dynamic
|
324 | 330 | # config function. Is only set once upon initialization.
|
325 | 331 | self._versioning_behavior: Optional[temporalio.common.VersioningBehavior] = None
|
@@ -1703,6 +1709,37 @@ def workflow_is_failure_exception(self, err: BaseException) -> bool:
|
1703 | 1709 | )
|
1704 | 1710 | )
|
1705 | 1711 |
|
| 1712 | + def workflow_has_last_completion_result(self) -> bool: |
| 1713 | + return len(self._last_completion_result.payloads) > 0 |
| 1714 | + |
| 1715 | + def workflow_last_completion_result( |
| 1716 | + self, type_hint: Optional[Type] |
| 1717 | + ) -> Optional[Any]: |
| 1718 | + if len(self._last_completion_result.payloads) == 0: |
| 1719 | + return None |
| 1720 | + elif len(self._last_completion_result.payloads) > 1: |
| 1721 | + warnings.warn( |
| 1722 | + f"Expected single last completion result, got {len(self._last_completion_result.payloads)}" |
| 1723 | + ) |
| 1724 | + return None |
| 1725 | + |
| 1726 | + if type_hint is None: |
| 1727 | + return self._payload_converter.from_payload( |
| 1728 | + self._last_completion_result.payloads[0] |
| 1729 | + ) |
| 1730 | + else: |
| 1731 | + return self._payload_converter.from_payload( |
| 1732 | + self._last_completion_result.payloads[0], type_hint |
| 1733 | + ) |
| 1734 | + |
| 1735 | + def workflow_last_failure(self) -> Optional[BaseException]: |
| 1736 | + if self._last_failure: |
| 1737 | + return self._failure_converter.from_failure( |
| 1738 | + self._last_failure, self._payload_converter |
| 1739 | + ) |
| 1740 | + |
| 1741 | + return None |
| 1742 | + |
1706 | 1743 | #### Calls from outbound impl ####
|
1707 | 1744 | # These are in alphabetical order and all start with "_outbound_".
|
1708 | 1745 |
|
@@ -2766,6 +2803,7 @@ def _apply_schedule_command(
|
2766 | 2803 | v.start_to_close_timeout.FromTimedelta(self._input.start_to_close_timeout)
|
2767 | 2804 | if self._input.retry_policy:
|
2768 | 2805 | self._input.retry_policy.apply_to_proto(v.retry_policy)
|
| 2806 | + |
2769 | 2807 | v.cancellation_type = cast(
|
2770 | 2808 | temporalio.bridge.proto.workflow_commands.ActivityCancellationType.ValueType,
|
2771 | 2809 | int(self._input.cancellation_type),
|
|
0 commit comments