Skip to content

Commit 8994624

Browse files
author
Alan Christie
committed
feat: Add get_running_workflow_step_by_name()
1 parent afd94c0 commit 8994624

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-0
lines changed

tests/test_test_api_adapter.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,3 +409,35 @@ def test_get_workflow_steps_driving_this_step_when_2nd_step():
409409
assert response["steps"][0]["name"] == "step-1"
410410
assert response["steps"][1]["name"] == "step-2"
411411
assert response["steps"][2]["name"] == "step-3"
412+
413+
414+
def test_get_running_workflow_step_by_name():
415+
# Arrange
416+
utaa = UnitTestWorkflowAPIAdapter()
417+
response = utaa.create_workflow(
418+
workflow_definition={
419+
"name": "blah",
420+
"steps": [{"name": "step-1"}, {"name": "step-2"}, {"name": "step-3"}],
421+
}
422+
)
423+
response = utaa.create_running_workflow(
424+
user_id="dlister",
425+
workflow_id=response["id"],
426+
project_id=TEST_PROJECT_ID,
427+
variables={},
428+
)
429+
rwf_id = response["id"]
430+
response, _ = utaa.create_running_workflow_step(
431+
running_workflow_id=rwf_id, step="step-2"
432+
)
433+
rwfs_id = response["id"]
434+
435+
# Act
436+
response, _ = utaa.get_running_workflow_step_by_name(
437+
name="step-2", running_workflow_id=rwf_id
438+
)
439+
440+
# Assert
441+
assert response["running_workflow"]["id"] == rwf_id
442+
assert response["name"] == "step-2"
443+
assert response["id"] == rwfs_id

tests/wapi_adapter.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,25 @@ def get_running_workflow_step(
178178
response["id"] = running_workflow_step_id
179179
return response, 0
180180

181+
def get_running_workflow_step_by_name(
182+
self, *, name: str, running_workflow_id: str
183+
) -> dict[str, Any]:
184+
UnitTestWorkflowAPIAdapter.lock.acquire()
185+
with open(_RUNNING_WORKFLOW_STEP_PICKLE_FILE, "rb") as pickle_file:
186+
running_workflow_step = Unpickler(pickle_file).load()
187+
UnitTestWorkflowAPIAdapter.lock.release()
188+
189+
print(f"name={name} running_workflow_id={running_workflow_id}")
190+
for rwfs_id, record in running_workflow_step.items():
191+
print(f"rwfs_id={rwfs_id} record={record}")
192+
if record["running_workflow"]["id"] != running_workflow_id:
193+
continue
194+
if record["name"] == name:
195+
response = record
196+
response["id"] = rwfs_id
197+
return response, 0
198+
return {}, 0
199+
181200
def set_running_workflow_step_variables(
182201
self,
183202
*,

workflow/workflow_abc.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,37 @@ def get_running_workflow_step(
242242
# "id": "r-workflow-step-00000000-0000-0000-0000-000000000001",
243243
# },
244244

245+
@abstractmethod
246+
def get_running_workflow_step_by_name(
247+
self, *, name: str, running_workflow_id: str
248+
) -> tuple[dict[str, Any], int]:
249+
"""Get a RunningWorkflowStep Record given a step name
250+
(and its RUnningWorkflow ID)"""
251+
# Should return:
252+
# {
253+
# "id": "r-workflow-step-00000000-0000-0000-0000-000000000001",
254+
# "name:": "step-1234",
255+
# "done": False,
256+
# "success": false,
257+
# "error_num": 0,
258+
# "error_msg": "",
259+
# "variables": {
260+
# "x": 1,
261+
# "y": 2,
262+
# },
263+
# "running_workflow": {
264+
# "id": "r-workflow-00000000-0000-0000-0000-000000000001",
265+
# },
266+
# }
267+
# If not present an empty dictionary should be returned.
268+
#
269+
# For steps that are not the first in a workflow the following field
270+
# can be expected in the response: -
271+
#
272+
# "prior_running_workflow_step": {
273+
# "id": "r-workflow-step-00000000-0000-0000-0000-000000000001",
274+
# },
275+
245276
@abstractmethod
246277
def set_running_workflow_step_variables(
247278
self,

0 commit comments

Comments
 (0)