Skip to content

Commit c99342e

Browse files
author
Peter Amstutz
committed
Runs stuff.
1 parent e642e77 commit c99342e

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

cwl_runner_wes.py

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,24 @@ def __init__(self, workflow_ID):
1616
self.workdir = os.path.abspath(self.workflow_ID)
1717

1818
def run(self, path, inputobj):
19+
path = os.path.abspath(path)
20+
os.mkdir(self.workdir)
1921
outdir = os.path.join(self.workdir, "outdir")
22+
os.mkdir(outdir)
2023
with open(os.path.join(self.workdir, "cwl.input.json"), "w") as inputtemp:
21-
json.dump(inputtemp, inputobj)
24+
json.dump(inputobj, inputtemp)
2225
with open(os.path.join(self.workdir, "workflow_url"), "w") as f:
2326
f.write(path)
2427
output = open(os.path.join(self.workdir, "cwl.output.json"), "w")
2528
stderr = open(os.path.join(self.workdir, "stderr"), "w")
2629

27-
proc = subprocess.Popen(["cwl-runner", path, inputtemp.name],
30+
#proc = subprocess.Popen(["cwl-runner", path, inputtemp.name],
31+
proc = subprocess.Popen(["cwltool", path, inputtemp.name],
2832
stdout=output,
2933
stderr=stderr,
3034
close_fds=True,
3135
cwd=outdir)
32-
stdout.close()
36+
output.close()
3337
stderr.close()
3438
with open(os.path.join(self.workdir, "pid"), "w") as pid:
3539
pid.write(str(proc.pid))
@@ -44,15 +48,20 @@ def getstate(self):
4448
if os.path.exists(exc):
4549
with open(exc) as f:
4650
exit_code = int(f.read())
47-
if exit_code == 0:
48-
state = "Complete"
49-
else:
50-
state = "Failed"
5151
else:
5252
with open(os.path.join(self.workdir, "pid"), "r") as pid:
5353
pid = int(pid.read())
5454
(_pid, exit_status) = os.waitpid(pid, os.WNOHANG)
55-
# record exit code
55+
if _pid != 0:
56+
exit_code = exit_status >> 8
57+
with open(exc, "w") as f:
58+
f.write(str(exit_code))
59+
os.unlink(os.path.join(self.workdir, "pid"))
60+
61+
if exit_code == 0:
62+
state = "Complete"
63+
elif exit_code != -1:
64+
state = "Failed"
5665

5766
return (state, exit_code)
5867

@@ -67,7 +76,7 @@ def getstatus(self):
6776
outputobj = None
6877
if state == "Complete":
6978
with open(os.path.join(self.workdir, "cwl.output.json"), "r") as outputtemp:
70-
outputtobj = json.load(outputtemp)
79+
outputobj = json.load(outputtemp)
7180

7281
return {
7382
"workflow_ID": self.workflow_ID,
@@ -81,14 +90,17 @@ def getstatus(self):
8190
def getlog(self):
8291
state, exit_code = self.getstate()
8392

93+
with open(os.path.join(self.workdir, "stderr"), "r") as f:
94+
stderr = f.read()
95+
8496
return {
8597
"workflow_ID": self.workflow_ID,
8698
"log": {
8799
"cmd": "",
88100
"startTime": "",
89101
"endTime": "",
90102
"stdout": "",
91-
"stderr": "",
103+
"stderr": stderr,
92104
"exitCode": exit_code
93105
}
94106
}
@@ -98,15 +110,16 @@ def cancel(self):
98110

99111
def GetWorkflowStatus(workflow_ID):
100112
job = Workflow(workflow_ID)
101-
job.getstatus()
113+
return job.getstatus()
102114

103115
def GetWorkflowLog(workflow_ID):
104116
job = Workflow(workflow_ID)
105-
job.getlog()
117+
return job.getlog()
106118

107119
def CancelWorkflow(workflow_ID):
108120
job = Workflow(workflow_ID)
109121
job.cancel()
122+
return job.getstatus()
110123

111124
def RunWorkflow(body):
112125
workflow_ID = uuid.uuid4().hex

0 commit comments

Comments
 (0)