Skip to content

Commit 4263159

Browse files
author
Alan Christie
committed
fix: Now handles optional variables (and ability to set step command)
1 parent 6eea849 commit 4263159

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

tests/wapi_adapter.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,23 @@ def get_running_workflow_step(
161161
response["id"] = running_workflow_step_id
162162
return response, 0
163163

164+
def set_running_workflow_step_command(
165+
self,
166+
*,
167+
running_workflow_step_id: str,
168+
command: str,
169+
) -> None:
170+
UnitTestWorkflowAPIAdapter.lock.acquire()
171+
with open(_RUNNING_WORKFLOW_STEP_PICKLE_FILE, "rb") as pickle_file:
172+
running_workflow_step = Unpickler(pickle_file).load()
173+
174+
assert running_workflow_step_id in running_workflow_step
175+
running_workflow_step[running_workflow_step_id]["command"] = command
176+
177+
with open(_RUNNING_WORKFLOW_STEP_PICKLE_FILE, "wb") as pickle_file:
178+
Pickler(pickle_file).dump(running_workflow_step)
179+
UnitTestWorkflowAPIAdapter.lock.release()
180+
164181
def set_running_workflow_step_done(
165182
self,
166183
*,

workflow/workflow_abc.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def get_running_workflow_step(
156156
"""Get a RunningWorkflowStep Record"""
157157
# Should return:
158158
# {
159-
# "step:": "step-1234",
159+
# "name:": "step-1234",
160160
# "done": False,
161161
# "success": false,
162162
# "error": None,
@@ -167,6 +167,15 @@ def get_running_workflow_step(
167167
# }
168168
# If not present an empty dictionary should be returned.
169169

170+
@abstractmethod
171+
def set_running_workflow_step_command(
172+
self,
173+
*,
174+
running_workflow_step_id: str,
175+
command: str,
176+
) -> None:
177+
"""Set the command value for a RunningWorkflowStep Record"""
178+
170179
@abstractmethod
171180
def set_running_workflow_step_done(
172181
self,

workflow/workflow_engine.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,17 +134,20 @@ def _handle_workflow_start_message(self, r_wfid: str) -> None:
134134
r_wfsid = response["id"]
135135

136136
# The step's 'specification' is a string - pass it directly to the
137-
# launcher along with any appropriate 'variables'. The launcher
137+
# launcher along with any (optional) 'variables'. The launcher
138138
# will apply the variables to step's Job command but we need to handle
139139
# any launch problems. The validator should have checked to ensure that
140140
# variable expansion will work, but we must prepare for the unexpected.
141141

142142
project_id = rwf_response["project"]["id"]
143-
variables = rwf_response["variables"]
143+
variables: dict[str, Any] | None = rwf_response.get("variables")
144144

145145
_LOGGER.info(
146-
"RunningWorkflow: %s (name=%s project=%s, variables=%s)",
146+
"Launching first step: RunningWorkflow=%s RunningWorkflowStep=%s step=%s"
147+
" (name=%s project=%s, variables=%s)",
147148
r_wfid,
149+
r_wfsid,
150+
first_step_name,
148151
rwf_response["name"],
149152
project_id,
150153
variables,
@@ -167,6 +170,11 @@ def _handle_workflow_start_message(self, r_wfid: str) -> None:
167170
first_step_name, r_wfid, r_wfsid, lr.error_num, lr.error_msg
168171
)
169172
else:
173+
if lr.command:
174+
self._wapi_adapter.set_running_workflow_step_command(
175+
running_workflow_step_id=r_wfsid,
176+
command=lr.command,
177+
)
170178
_LOGGER.info(
171179
"Launched first step '%s' (command=%s)", first_step_name, lr.command
172180
)

0 commit comments

Comments
 (0)