Skip to content

Commit c357057

Browse files
committed
minor change
Signed-off-by: Tim Li <[email protected]>
1 parent a96acbf commit c357057

File tree

2 files changed

+14
-67
lines changed

2 files changed

+14
-67
lines changed

cadence/client.py

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,6 @@
2323
from cadence.metrics import MetricsEmitter, NoOpMetricsEmitter
2424

2525

26-
@dataclass
27-
class WorkflowRun:
28-
"""Represents a workflow run that can be used to get results."""
29-
execution: WorkflowExecution
30-
client: 'Client'
31-
32-
@property
33-
def workflow_id(self) -> str:
34-
"""Get the workflow ID."""
35-
return self.execution.workflow_id
36-
37-
@property
38-
def run_id(self) -> str:
39-
"""Get the run ID."""
40-
return self.execution.run_id
41-
42-
async def get_result(self, result_type: Optional[type] = None) -> Any: # noqa: ARG002
43-
"""Wait for workflow completion and return result."""
44-
# TODO: Implement workflow result retrieval
45-
# This would involve polling GetWorkflowExecutionHistory until completion
46-
# and extracting the result from the final event
47-
raise NotImplementedError("get_result not yet implemented")
48-
4926

5027
@dataclass
5128
class StartWorkflowOptions:
@@ -246,28 +223,25 @@ async def execute_workflow(
246223
workflow: Union[str, Callable],
247224
*args,
248225
**options_kwargs
249-
) -> WorkflowRun:
226+
) -> WorkflowExecution:
250227
"""
251-
Start a workflow execution and return a handle to get the result.
228+
Start a workflow execution and return the execution handle.
252229
253230
Args:
254231
workflow: Workflow function or workflow type name string
255232
*args: Arguments to pass to the workflow
256233
**options_kwargs: StartWorkflowOptions as keyword arguments
257234
258235
Returns:
259-
WorkflowRun that can be used to get the workflow result
236+
WorkflowExecution that contains workflow_id and run_id
260237
261238
Raises:
262239
ValueError: If required parameters are missing or invalid
263240
Exception: If the gRPC call fails
264241
"""
265-
execution = await self.start_workflow(workflow, *args, **options_kwargs)
242+
return await self.start_workflow(workflow, *args, **options_kwargs)
243+
266244

267-
return WorkflowRun(
268-
execution=execution,
269-
client=self
270-
)
271245

272246
def _validate_and_copy_defaults(options: ClientOptions) -> ClientOptions:
273247
if "target" not in options:

tests/cadence/test_client_workflow.py

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from cadence.api.v1.common_pb2 import WorkflowExecution
77
from cadence.api.v1.service_workflow_pb2 import StartWorkflowExecutionRequest, StartWorkflowExecutionResponse
88
from cadence.api.v1.workflow_pb2 import WorkflowIdReusePolicy
9-
from cadence.client import Client, StartWorkflowOptions, WorkflowRun
9+
from cadence.client import Client, StartWorkflowOptions
1010
from cadence.data_converter import DefaultDataConverter
1111

1212

@@ -64,32 +64,6 @@ def test_custom_values(self):
6464
assert options.search_attributes == {"attr": "value"}
6565

6666

67-
class TestWorkflowRun:
68-
"""Test WorkflowRun class."""
69-
70-
def test_properties(self, mock_client):
71-
"""Test WorkflowRun properties."""
72-
execution = WorkflowExecution()
73-
execution.workflow_id = "test-workflow-id"
74-
execution.run_id = "test-run-id"
75-
76-
workflow_run = WorkflowRun(execution=execution, client=mock_client)
77-
78-
assert workflow_run.workflow_id == "test-workflow-id"
79-
assert workflow_run.run_id == "test-run-id"
80-
assert workflow_run.client is mock_client
81-
82-
@pytest.mark.asyncio
83-
async def test_get_result_not_implemented(self, mock_client):
84-
"""Test that get_result raises NotImplementedError."""
85-
execution = WorkflowExecution()
86-
execution.workflow_id = "test-workflow-id"
87-
execution.run_id = "test-run-id"
88-
89-
workflow_run = WorkflowRun(execution=execution, client=mock_client)
90-
91-
with pytest.raises(NotImplementedError, match="get_result not yet implemented"):
92-
await workflow_run.get_result()
9367

9468

9569
class TestClientBuildStartWorkflowRequest:
@@ -316,17 +290,16 @@ async def test_execute_workflow_success(self, mock_client):
316290
client = Client(domain="test-domain", target="localhost:7933")
317291
client.start_workflow = AsyncMock(return_value=execution)
318292

319-
workflow_run = await client.execute_workflow(
293+
result_execution = await client.execute_workflow(
320294
"TestWorkflow",
321295
"arg1", "arg2",
322296
task_list="test-task-list"
323297
)
324298

325-
assert isinstance(workflow_run, WorkflowRun)
326-
assert workflow_run.execution is execution
327-
assert workflow_run.client is client
328-
assert workflow_run.workflow_id == "test-workflow-id"
329-
assert workflow_run.run_id == "test-run-id"
299+
assert isinstance(result_execution, WorkflowExecution)
300+
assert result_execution is execution
301+
assert result_execution.workflow_id == "test-workflow-id"
302+
assert result_execution.run_id == "test-run-id"
330303

331304
# Verify start_workflow was called with correct arguments
332305
client.start_workflow.assert_called_once_with(
@@ -361,7 +334,7 @@ async def test_integration_workflow_invocation():
361334
client._workflow_stub.StartWorkflowExecution = AsyncMock(return_value=response)
362335

363336
# Test the complete flow
364-
workflow_run = await client.execute_workflow(
337+
execution = await client.execute_workflow(
365338
"IntegrationTestWorkflow",
366339
"test-arg",
367340
42,
@@ -372,8 +345,8 @@ async def test_integration_workflow_invocation():
372345
)
373346

374347
# Verify result
375-
assert workflow_run.workflow_id == "integration-workflow-id"
376-
assert workflow_run.run_id == "integration-run-id"
348+
assert execution.workflow_id == "integration-workflow-id"
349+
assert execution.run_id == "integration-run-id"
377350

378351
# Verify the gRPC call was made with proper request
379352
client._workflow_stub.StartWorkflowExecution.assert_called_once()

0 commit comments

Comments
 (0)