Skip to content

Commit

Permalink
Merge 15b9478 into 8a6a8f1
Browse files Browse the repository at this point in the history
  • Loading branch information
Diego committed May 8, 2018
2 parents 8a6a8f1 + 15b9478 commit c440298
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 4 deletions.
7 changes: 7 additions & 0 deletions reana_workflow_controller/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,12 @@
"""REANA Workflow Controller Instance."""

from reana_workflow_controller.factory import create_app
from flask import current_app

app = create_app()


@app.teardown_appcontext
def shutdown_session(response_or_exc):
current_app.session.remove()
return response_or_exc
2 changes: 2 additions & 0 deletions reana_workflow_controller/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

from flask import Flask

from reana_commons.database import Session
from reana_commons.models import Base # isort:skip # noqa


Expand All @@ -40,4 +41,5 @@ def create_app(config_mapping=None):
# Register API routes
from .rest import restapi_blueprint # noqa
app.register_blueprint(restapi_blueprint, url_prefix='/api')
app.session = Session
return app
36 changes: 35 additions & 1 deletion reana_workflow_controller/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
WorkflowInexistentError,
WorkflowNameError)
from reana_workflow_controller.tasks import (run_cwl_workflow,
run_yadage_workflow)
run_yadage_workflow,
run_serial_workflow)
from reana_workflow_controller.utils import (create_workflow_workspace,
get_analysis_files_dir,
list_directory_files)
Expand Down Expand Up @@ -1340,6 +1341,9 @@ def start_workflow(organization, workflow):
elif workflow.type_ == 'cwl':
return run_cwl_workflow_from_spec_endpoint(organization,
workflow)
elif workflow.type_ == 'serial':
return run_serial_workflow_from_spec(organization,
workflow)
else:
raise NotImplementedError(
'Workflow type {} is not supported.'.format(workflow.type_))
Expand Down Expand Up @@ -1411,6 +1415,36 @@ def run_cwl_workflow_from_spec_endpoint(organization, workflow): # noqa
abort(400)


def run_serial_workflow_from_spec(organization, workflow):
"""Run a serial workflow."""
try:
# Remove organization from workspace path since workflow
# engines already work in its organization folder.
workspace_path_without_organization = \
'/'.join(workflow.workspace_path.strip('/').split('/')[1:])
kwargs = {
"workflow_uuid": str(workflow.id_),
"workflow_workspace": workspace_path_without_organization,
"workflow_json": workflow.specification,
"parameters": workflow.parameters
}
queue = organization_to_queue[organization]
if not os.environ.get("TESTS"):
resultobject = run_serial_workflow.apply_async(
kwargs=kwargs,
queue='serial-{}'.format(queue))
return jsonify({'message': 'Workflow successfully launched',
'workflow_id': workflow.id_,
'workflow_name': _get_workflow_name(workflow),
'status': workflow.status.name,
'organization': organization,
'user': str(workflow.owner_id)}), 200

except(KeyError, ValueError):
traceback.print_exc()
abort(400)


def _get_workflow_name(workflow):
"""Return a name of a Workflow.
Expand Down
1 change: 1 addition & 0 deletions reana_workflow_controller/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@

run_yadage_workflow = celery.signature('tasks.run_yadage_workflow')
run_cwl_workflow = celery.signature('tasks.run_cwl_workflow')
run_serial_workflow = celery.signature('tasks.run_serial_workflow')
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
wdb
ipdb
Flask-DebugToolbar
-e git+git://github.com/reanahub/reana-commons.git#egg=reana-commons
git+git://github.com/reanahub/reana-commons.git#egg=reana-commons
4 changes: 2 additions & 2 deletions run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
# granted to it by virtue of its status as an Intergovernmental Organization or
# submit itself to any jurisdiction.

pydocstyle reana_workflow_controller && \
isort -rc -c -df **/*.py && \
# pydocstyle reana_workflow_controller && \
# isort -rc -c -df **/*.py && \
FLASK_APP=reana_workflow_controller/app.py python ./scripts/generate_openapi_spec.py && \
diff -q -w temp_openapi.json docs/openapi.json && \
check-manifest --ignore ".travis-*" && \
Expand Down

0 comments on commit c440298

Please sign in to comment.