-
Notifications
You must be signed in to change notification settings - Fork 140
Additional high-level describe details #72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,7 @@ | |
| import uuid | ||
| import warnings | ||
| from dataclasses import dataclass | ||
| from datetime import timedelta | ||
| from datetime import datetime, timedelta, timezone | ||
| from enum import IntEnum | ||
| from typing import ( | ||
| Any, | ||
|
|
@@ -865,7 +865,7 @@ async def cancel(self) -> None: | |
|
|
||
| async def describe( | ||
| self, | ||
| ) -> WorkflowDescription: | ||
| ) -> WorkflowExecutionDescription: | ||
| """Get workflow details. | ||
|
|
||
| This will get details for :py:attr:`run_id` if present. To use a | ||
|
|
@@ -1165,29 +1165,68 @@ async def report_cancellation(self, *details: Any) -> None: | |
| ) | ||
|
|
||
|
|
||
| class WorkflowDescription: | ||
| """Description for a workflow.""" | ||
|
|
||
| def __init__( | ||
| self, | ||
| raw_message: temporalio.api.workflowservice.v1.DescribeWorkflowExecutionResponse, | ||
| ): | ||
| """Create a workflow description from a describe response.""" | ||
| self._raw_message = raw_message | ||
| status = raw_message.workflow_execution_info.status | ||
| self._status = WorkflowExecutionStatus(status) if status else None | ||
| @dataclass | ||
| class WorkflowExecutionDescription: | ||
| """Description for a workflow execution.""" | ||
|
|
||
| @property | ||
| def raw_message( | ||
| self, | ||
| ) -> temporalio.api.workflowservice.v1.DescribeWorkflowExecutionResponse: | ||
| """Underlying workflow description response.""" | ||
| return self._raw_message | ||
| close_time: Optional[datetime] | ||
| execution_time: Optional[datetime] | ||
| history_length: int | ||
| id: str | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should probably be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In Python we have used |
||
| memo: Mapping[str, Any] | ||
| parent_id: Optional[str] | ||
| parent_run_id: Optional[str] | ||
| raw: temporalio.api.workflowservice.v1.DescribeWorkflowExecutionResponse | ||
| run_id: str | ||
| search_attributes: temporalio.common.SearchAttributes | ||
| start_time: datetime | ||
| status: Optional[WorkflowExecutionStatus] | ||
| task_queue: str | ||
| workflow: str | ||
cretz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| @property | ||
| def status(self) -> Optional[WorkflowExecutionStatus]: | ||
| """Status of the workflow.""" | ||
| return self._status | ||
| @staticmethod | ||
| async def from_raw( | ||
| raw: temporalio.api.workflowservice.v1.DescribeWorkflowExecutionResponse, | ||
| converter: temporalio.converter.DataConverter, | ||
| ) -> WorkflowExecutionDescription: | ||
| """Create a description from a raw description response.""" | ||
| return WorkflowExecutionDescription( | ||
| close_time=raw.workflow_execution_info.close_time.ToDatetime().replace( | ||
| tzinfo=timezone.utc | ||
| ) | ||
| if raw.workflow_execution_info.HasField("close_time") | ||
| else None, | ||
| execution_time=raw.workflow_execution_info.execution_time.ToDatetime().replace( | ||
| tzinfo=timezone.utc | ||
| ) | ||
| if raw.workflow_execution_info.HasField("execution_time") | ||
| else None, | ||
| history_length=raw.workflow_execution_info.history_length, | ||
| id=raw.workflow_execution_info.execution.workflow_id, | ||
| memo={ | ||
| k: (await converter.decode([v]))[0] | ||
| for k, v in raw.workflow_execution_info.memo.fields.items() | ||
| }, | ||
| parent_id=raw.workflow_execution_info.parent_execution.workflow_id | ||
| if raw.workflow_execution_info.HasField("parent_execution") | ||
| else None, | ||
| parent_run_id=raw.workflow_execution_info.parent_execution.run_id | ||
| if raw.workflow_execution_info.HasField("parent_execution") | ||
| else None, | ||
| raw=raw, | ||
| run_id=raw.workflow_execution_info.execution.run_id, | ||
| search_attributes=temporalio.converter.decode_search_attributes( | ||
| raw.workflow_execution_info.search_attributes | ||
| ), | ||
| start_time=raw.workflow_execution_info.start_time.ToDatetime().replace( | ||
| tzinfo=timezone.utc | ||
| ), | ||
| status=WorkflowExecutionStatus(raw.workflow_execution_info.status) | ||
| if raw.workflow_execution_info.status | ||
| else None, | ||
| task_queue=raw.workflow_execution_info.task_queue, | ||
| workflow=raw.workflow_execution_info.type.name, | ||
| ) | ||
|
|
||
|
|
||
| class WorkflowExecutionStatus(IntEnum): | ||
|
|
@@ -1437,7 +1476,7 @@ async def cancel_workflow(self, input: CancelWorkflowInput) -> None: | |
|
|
||
| async def describe_workflow( | ||
| self, input: DescribeWorkflowInput | ||
| ) -> WorkflowDescription: | ||
| ) -> WorkflowExecutionDescription: | ||
| """Called for every :py:meth:`WorkflowHandle.describe` call.""" | ||
|
|
||
| async def query_workflow(self, input: QueryWorkflowInput) -> Any: | ||
|
|
@@ -1525,16 +1564,18 @@ async def start_workflow( | |
| req.cron_schedule = input.cron_schedule | ||
| if input.memo is not None: | ||
| for k, v in input.memo.items(): | ||
| req.memo.fields[k] = (await self._client.data_converter.encode([v]))[0] | ||
| req.memo.fields[k].CopyFrom( | ||
| (await self._client.data_converter.encode([v]))[0] | ||
| ) | ||
| if input.search_attributes is not None: | ||
| temporalio.converter.encode_search_attributes( | ||
| input.search_attributes, req.search_attributes | ||
| ) | ||
| if input.header is not None: | ||
| for k, v in input.header.items(): | ||
| req.header.fields[k] = (await self._client.data_converter.encode([v]))[ | ||
| 0 | ||
| ] | ||
| req.header.fields[k].CopyFrom( | ||
| (await self._client.data_converter.encode([v]))[0] | ||
| ) | ||
|
|
||
| # Start with signal or just normal start | ||
| resp: Union[ | ||
|
|
@@ -1577,8 +1618,8 @@ async def cancel_workflow(self, input: CancelWorkflowInput) -> None: | |
|
|
||
| async def describe_workflow( | ||
| self, input: DescribeWorkflowInput | ||
| ) -> WorkflowDescription: | ||
| return WorkflowDescription( | ||
| ) -> WorkflowExecutionDescription: | ||
| return await WorkflowExecutionDescription.from_raw( | ||
| await self._client.service.describe_workflow_execution( | ||
| temporalio.api.workflowservice.v1.DescribeWorkflowExecutionRequest( | ||
| namespace=self._client.namespace, | ||
|
|
@@ -1588,7 +1629,8 @@ async def describe_workflow( | |
| ), | ||
| ), | ||
| retry=True, | ||
| ) | ||
| ), | ||
| self._client.data_converter, | ||
| ) | ||
|
|
||
| async def query_workflow(self, input: QueryWorkflowInput) -> Any: | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.