Skip to content

Commit fed4ece

Browse files
author
Peter Amstutz
committed
Proof of concept web service for accepting CWL job requests.
1 parent 7ffb939 commit fed4ece

File tree

4 files changed

+66
-44
lines changed

4 files changed

+66
-44
lines changed

cwl_client.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import argparse
2+
import requests
3+
4+
def main():
5+
parser = argparse.ArgumentParser()
6+
7+
parser.add_argument("--upload", action="store_true")
8+
parser.add_argument("endpoint")
9+
parser.add_argument("object")
10+
11+
args = parser.parse_args()
12+
13+
if args.upload:
14+
r = requests.put(args.endpoint)
15+
else:
16+
r = requests.post(args.endpoint)
17+
18+
if __name__ == "__main__":
19+
main()

cwltool_flask.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import cwltool
2+
from flask import Flask
3+
from flask import request
4+
import os
5+
import StringIO
6+
7+
app = Flask(__name__)
8+
9+
@app.route("/<workflow>", methods=['GET', 'POST', 'PUT'])
10+
def runjob(workflow):
11+
try:
12+
if request.method == 'PUT':
13+
with open(os.path.join("files", workflow), "w") as f:
14+
f.write(request.stream.read())
15+
return "Ok"
16+
17+
wf = os.path.join("files", workflow)
18+
19+
if not os.path.exists(wf):
20+
return "Not found", 404
21+
22+
if request.method == 'POST':
23+
out = StringIO.StringIO()
24+
err = StringIO.StringIO()
25+
if cwltool.main(args=[wf, "-"],
26+
stdin=request.stream.read(),
27+
stdout=out,
28+
stderr=err) != 0:
29+
return err.getvalue(), 400
30+
else:
31+
return out.getvalue()
32+
33+
else:
34+
with open(wf, "r") as f:
35+
return f.read()
36+
except Exception as e:
37+
return str(e), 500
38+
39+
if __name__ == "__main__":
40+
if not os.path.exists("files"):
41+
os.mkdir("files")
42+
app.run()

cwltool_service.py

Lines changed: 0 additions & 41 deletions
This file was deleted.

setup.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,19 @@
1111
README = os.path.join(SETUP_DIR, 'README')
1212

1313
setup(name='cwltool_service',
14-
version='1.0.2',
14+
version='1.0.3',
1515
description='Common workflow language runner service',
1616
long_description=open(README).read(),
1717
author='Common workflow language working group',
1818
author_email='[email protected]',
1919
url="https://github.com/common-workflow-language/common-workflow-language",
2020
download_url="https://github.com/common-workflow-language/common-workflow-language",
2121
license='Apache 2.0',
22-
py_modules=["cwltool_service"],
22+
py_modules=["cwltool_stream", "cwltool_flask", "cwltool_client"],
2323
install_requires=[
24-
'cwltool'
24+
'cwltool >= 1.0.20151013135545',
25+
'Flask',
26+
'requests'
2527
],
2628
entry_points={
2729
'console_scripts': [ "cwltool-service=cwltool_service:main" ]

0 commit comments

Comments
 (0)