Skip to content

Commit 7841e1b

Browse files
author
Peter Amstutz
committed
Record logs from arvados-cwl-runner to report them back to WES.
1 parent 3cc066d commit 7841e1b

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

wes_client/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def fixpaths(d):
139139

140140
s = client.WorkflowExecutionService.GetWorkflowLog(
141141
workflow_id=r["workflow_id"]).result()
142-
logging.info(s["workflow_log"]["stderr"])
142+
logging.info("Workflow log:\n"+s["workflow_log"]["stderr"])
143143

144144
if "fields" in s["outputs"] and s["outputs"]["fields"] is None:
145145
del s["outputs"]["fields"]

wes_service/arvados_wes.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,20 +82,29 @@ def ListWorkflows(self):
8282
}
8383

8484
def invoke_cwl_runner(self, cr_uuid, workflow_url, workflow_params, env):
85+
api = arvados.api_from_config(version="v1", apiconfig={
86+
"ARVADOS_API_HOST": env["ARVADOS_API_HOST"],
87+
"ARVADOS_API_TOKEN": env['ARVADOS_API_TOKEN'],
88+
"ARVADOS_API_HOST_INSECURE": env["ARVADOS_API_HOST_INSECURE"] # NOQA
89+
})
90+
8591
try:
8692
with tempfile.NamedTemporaryFile() as inputtemp:
8793
json.dump(workflow_params, inputtemp)
8894
inputtemp.flush()
89-
workflow_id = subprocess.check_output(["arvados-cwl-runner", "--submit-request-uuid="+cr_uuid, # NOQA
95+
proc = subprocess.Popen(["arvados-cwl-runner", "--submit-request-uuid="+cr_uuid, # NOQA
9096
"--submit", "--no-wait", "--api=containers", # NOQA
91-
workflow_url, inputtemp.name], env=env).strip() # NOQA
97+
workflow_url, inputtemp.name], env=env,
98+
stdout=subprocess.PIPE, stderr=subprocess.PIPE) # NOQA
99+
(stdoutdata, stderrdata) = proc.communicate()
100+
if proc.returncode != 0:
101+
api.container_requests().update(uuid=cr_uuid, body={"priority": 0,
102+
"properties": {"arvados-cwl-runner-log": stderrdata}}).execute()
103+
else:
104+
api.container_requests().update(uuid=cr_uuid, body={"properties": {"arvados-cwl-runner-log": stderrdata}}).execute()
92105
except subprocess.CalledProcessError as e:
93-
api = arvados.api_from_config(version="v1", apiconfig={
94-
"ARVADOS_API_HOST": env["ARVADOS_API_HOST"],
95-
"ARVADOS_API_TOKEN": env['ARVADOS_API_TOKEN'],
96-
"ARVADOS_API_HOST_INSECURE": env["ARVADOS_API_HOST_INSECURE"] # NOQA
97-
})
98-
request = api.container_requests().update(uuid=cr_uuid, body={"priority": 0}).execute() # NOQA
106+
api.container_requests().update(uuid=cr_uuid, body={"priority": 0,
107+
"properties": {"arvados-cwl-runner-log": str(e)}}).execute()
99108

100109
@catch_exceptions
101110
def RunWorkflow(self, body):
@@ -132,6 +141,8 @@ def GetWorkflowLog(self, workflow_id):
132141
else:
133142
container = {"state": "Queued", "exit_code": None}
134143

144+
stderr = request["properties"].get("arvados-cwl-runner-log", "")
145+
135146
outputobj = {}
136147
if request["output_uuid"]:
137148
c = arvados.collection.CollectionReader(request["output_uuid"], api_client=api)
@@ -144,12 +155,11 @@ def keepref(d):
144155

145156
visit(outputobj, keepref)
146157

147-
stderr = ""
148158
if request["log_uuid"]:
149159
c = arvados.collection.CollectionReader(request["log_uuid"], api_client=api)
150160
if "stderr.txt" in c:
151161
with c.open("stderr.txt") as f:
152-
stderr = f.read()
162+
stderr += f.read()
153163

154164
r = {
155165
"workflow_id": request["uuid"],

0 commit comments

Comments
 (0)