Skip to content

Commit 113d61b

Browse files
author
Alan Christie
committed
feat: API adapter now supports set_running_workflow_step_variables()
1 parent 9c5e183 commit 113d61b

File tree

3 files changed

+45
-3
lines changed

3 files changed

+45
-3
lines changed

tests/test_test_api_adapter.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,31 @@ def test_create_running_workflow_step():
163163
assert response["id"] == "r-workflow-step-00000000-0000-0000-0000-000000000001"
164164

165165

166+
def test_set_running_workflow_step_variables():
167+
# Arrange
168+
utaa = UnitTestWorkflowAPIAdapter()
169+
response = utaa.create_workflow(workflow_definition={"name": "blah"})
170+
response = utaa.create_running_workflow(
171+
user_id="dlister",
172+
workflow_id=response["id"],
173+
project_id=TEST_PROJECT_ID,
174+
variables={},
175+
)
176+
response, _ = utaa.create_running_workflow_step(
177+
running_workflow_id=response["id"], step="step-1"
178+
)
179+
rwfsid = response["id"]
180+
181+
# Act
182+
utaa.set_running_workflow_step_variables(
183+
running_workflow_step_id=rwfsid, variables={"z": 42}
184+
)
185+
186+
# Assert
187+
response, _ = utaa.get_running_workflow_step(running_workflow_step_id=rwfsid)
188+
assert response["variables"] == {"z": 42}
189+
190+
166191
def test_set_running_workflow_step_done_when_success():
167192
# Arrange
168193
utaa = UnitTestWorkflowAPIAdapter()
@@ -187,6 +212,7 @@ def test_set_running_workflow_step_done_when_success():
187212
assert response["success"]
188213
assert response["error"] is None
189214
assert response["error_msg"] is None
215+
assert response["variables"] == {}
190216

191217

192218
def test_set_running_workflow_step_done_when_failed():

tests/wapi_adapter.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ def create_running_workflow_step(
137137
"name": step,
138138
"done": False,
139139
"success": False,
140+
"variables": {},
140141
"running_workflow": {"id": running_workflow_id},
141142
}
142143
running_workflow_step[running_workflow_step_id] = record
@@ -161,18 +162,18 @@ def get_running_workflow_step(
161162
response["id"] = running_workflow_step_id
162163
return response, 0
163164

164-
def set_running_workflow_step_command(
165+
def set_running_workflow_step_variables(
165166
self,
166167
*,
167168
running_workflow_step_id: str,
168-
command: str,
169+
variables: dict[str, Any],
169170
) -> None:
170171
UnitTestWorkflowAPIAdapter.lock.acquire()
171172
with open(_RUNNING_WORKFLOW_STEP_PICKLE_FILE, "rb") as pickle_file:
172173
running_workflow_step = Unpickler(pickle_file).load()
173174

174175
assert running_workflow_step_id in running_workflow_step
175-
running_workflow_step[running_workflow_step_id]["command"] = command
176+
running_workflow_step[running_workflow_step_id]["variables"] = variables
176177

177178
with open(_RUNNING_WORKFLOW_STEP_PICKLE_FILE, "wb") as pickle_file:
178179
Pickler(pickle_file).dump(running_workflow_step)

workflow/workflow_abc.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,27 @@ def get_running_workflow_step(
186186
# "success": false,
187187
# "error": None,
188188
# "error_msg": None,
189+
# "variables": {
190+
# "x": 1,
191+
# "y": 2,
192+
# },
189193
# "running_workflow": {
190194
# "id": "r-workflow-00000000-0000-0000-0000-000000000001"
191195
# },
192196
# }
193197
# If not present an empty dictionary should be returned.
194198

199+
@abstractmethod
200+
def set_running_workflow_step_variables(
201+
self,
202+
*,
203+
running_workflow_step_id: str,
204+
variables: dict[str, Any],
205+
) -> None:
206+
"""Set the variables used prior to decoding the step command for each step.
207+
This can be used to understand step failures but will also be vital
208+
when adding variables values to subsequent steps from prior step values."""
209+
195210
@abstractmethod
196211
def set_running_workflow_step_done(
197212
self,

0 commit comments

Comments
 (0)