Skip to content

Commit 8a909d3

Browse files
N-giveNathan Givens
andauthored
IWF-693 return workflow run id when starting a workflow (#92)
* IWF-693 return workflow run id when starting a workflow --------- Co-authored-by: Nathan Givens <[email protected]>
1 parent 561c1cf commit 8a909d3

File tree

3 files changed

+30
-10
lines changed

3 files changed

+30
-10
lines changed

iwf/client.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def start_workflow(
5555
timeout_seconds: int,
5656
input: Any = None,
5757
options: Optional[WorkflowOptions] = None,
58-
) -> None:
58+
) -> str:
5959
"""
6060
6161
Args:
@@ -65,6 +65,9 @@ def start_workflow(
6565
input: input of the workflow, aka, the input of the starting state of the workflow
6666
options: advanced options
6767
68+
Returns:
69+
workflow_run_id: the run id of the started workflow
70+
6871
Raises:
6972
ClientSideError for non-retryable error
7073
ServerSideError for server error
@@ -114,7 +117,7 @@ def start_workflow(
114117
)
115118
unreg_opts.start_state_options = starting_state_opts
116119

117-
self._unregistered_client.start_workflow(
120+
return self._unregistered_client.start_workflow(
118121
wf_type, wf_id, starting_state_id, timeout_seconds, input, unreg_opts
119122
)
120123

iwf/tests/test_basic_workflow.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,15 @@ def test_basic_workflow(self):
8585
workflow_already_started_options_1
8686
)
8787

88-
client.start_workflow(BasicWorkflow, wf_id, 100, "input", start_options_1)
88+
wf_run_id = client.start_workflow(
89+
BasicWorkflow, wf_id, 100, "input", start_options_1
90+
)
91+
assert wf_run_id
8992

90-
client.start_workflow(BasicWorkflow, wf_id, 100, "input", start_options_1)
93+
wf_run_id = client.start_workflow(
94+
BasicWorkflow, wf_id, 100, "input", start_options_1
95+
)
96+
assert wf_run_id
9197

9298
workflow_already_started_options_2 = WorkflowAlreadyStartedOptions(
9399
ignore_already_started_error=True
@@ -100,7 +106,10 @@ def test_basic_workflow(self):
100106
)
101107

102108
with self.assertRaises(WorkflowAlreadyStartedError):
103-
client.start_workflow(BasicWorkflow, wf_id, 100, "input", start_options_2)
109+
wf_run_id = client.start_workflow(
110+
BasicWorkflow, wf_id, 100, "input", start_options_2
111+
)
112+
assert wf_run_id
104113

105-
res = client.get_simple_workflow_result_with_wait(wf_id, str)
114+
res = client.wait_for_workflow_completion(wf_id, str)
106115
assert res == "done"

iwf/unregistered_client.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
WorkflowSetSearchAttributesRequest,
6262
WorkflowWaitForStateCompletionRequest,
6363
)
64+
from iwf.iwf_api.models.workflow_start_response import WorkflowStartResponse
6465
from iwf.iwf_api.types import Response
6566
from iwf.reset_workflow_type_and_options import ResetWorkflowTypeAndOptions
6667
from iwf.stop_workflow_options import StopWorkflowOptions
@@ -193,11 +194,18 @@ def start_workflow(
193194
options.wait_for_completion_state_ids
194195
)
195196

196-
response = post_api_v1_workflow_start.sync_detailed(
197-
client=self.api_client,
198-
json_body=request,
197+
workflow_start_response = handler_error_and_return(
198+
post_api_v1_workflow_start.sync_detailed(
199+
client=self.api_client,
200+
json_body=request,
201+
)
199202
)
200-
return handler_error_and_return(response)
203+
if workflow_start_response is None or not isinstance(
204+
workflow_start_response, WorkflowStartResponse
205+
):
206+
raise RuntimeError("Failed to parse WorkflowStartResponse")
207+
208+
return workflow_start_response.workflow_run_id
201209

202210
def get_simple_workflow_result_with_wait(
203211
self,

0 commit comments

Comments
 (0)