Commit a7843bb0 authored by David Mendez's avatar David Mendez
Browse files

Call job submission function from new submission controller

parent fd9e0293
......@@ -8,6 +8,7 @@ from app.config import RUN_CONFIG
from app.config import RunEnvs
from app.db import DB
from app.blueprints.swagger_description.swagger_description_blueprint import SWAGGER_BLUEPRINT
from app.blueprints.job_submission.controllers.job_submissions_controller import SUBMISSION_BLUEPRINT
def create_app():
......@@ -49,6 +50,7 @@ def create_app():
base_path = RUN_CONFIG.get('base_path', '')
flask_app.register_blueprint(SWAGGER_BLUEPRINT, url_prefix=f'{base_path}/swagger')
flask_app.register_blueprint(SUBMISSION_BLUEPRINT, url_prefix=f'{base_path}/submit')
......
"""
The blueprint used in job submission
"""
from flask import Blueprint, jsonify, request
from app.models import delayed_job_models
from app.blueprints.job_submission.services import job_submission_service
SUBMISSION_BLUEPRINT = Blueprint('job_submission', __name__)
@SUBMISSION_BLUEPRINT.route('/test_job', methods = ['POST'])
def submit_test_job():
job_type = delayed_job_models.JobTypes.TEST
docker_image_url = 'docker://dockerhub.ebi.ac.uk/chembl/chembl/delayed-jobs/test-job:latest'
response = job_submission_service.parse_args_and_submit_job(job_type, request.form, request.files, docker_image_url)
return jsonify(response)
\ No newline at end of file
......@@ -70,43 +70,29 @@ def get_input_files_hashes(input_files_desc):
return input_files_hashes
def get_job_input_files_desc_only(args):
def get_job_input_files_desc(args):
"""
Saves the input files to a temporary directory to not depend from flask-respx implementation, then returns a
structure describing them.
:param args: args sent to the endpoint from flask rest-plus
:param args: files sent to the endpoint from flask
:return: dict with the input files and their temporary location
"""
input_files_desc = {}
for param_key, parameter in args.items():
if isinstance(parameter, werkzeug.datastructures.FileStorage):
tmp_dir = Path.joinpath(Path(JOBS_TMP_DIR), f'{random.randint(1, 1000000)}')
os.makedirs(tmp_dir, exist_ok=True)
tmp_path = Path.joinpath(Path(tmp_dir), parameter.filename)
parameter.save(str(tmp_path))
input_files_desc[param_key] = str(tmp_path)
tmp_dir = Path.joinpath(Path(JOBS_TMP_DIR), f'{random.randint(1, 1000000)}')
os.makedirs(tmp_dir, exist_ok=True)
tmp_path = Path.joinpath(Path(tmp_dir), parameter.filename)
parameter.save(str(tmp_path))
input_files_desc[param_key] = str(tmp_path)
return input_files_desc
def get_job_params_only(args):
"""
:param args: args sent to the endpoint from flask rest-plus
:return: dict the parameters that are not files
"""
job_params = {}
for param_key, parameter in args.items():
if not isinstance(parameter, werkzeug.datastructures.FileStorage):
job_params[param_key] = parameter
return job_params
def parse_args_and_submit_job(job_type, args, docker_image_url):
def parse_args_and_submit_job(job_type, form_args, file_args, docker_image_url):
job_params_only = get_job_params_only(args)
job_inputs_only = get_job_input_files_desc_only(args)
job_params_only = {param_key: parameter for (param_key, parameter) in form_args.items()}
job_inputs_only = get_job_input_files_desc(file_args)
input_files_hashes = get_input_files_hashes(job_inputs_only)
return submit_job(job_type, job_inputs_only, input_files_hashes, docker_image_url, job_params_only)
......
......@@ -13,7 +13,6 @@ SWAGGER_BLUEPRINT = Blueprint('swagger', __name__)
@SWAGGER_BLUEPRINT.route('/swagger.json')
def get_json():
# with open("example.yaml", 'r') as stream:
yaml_file_path = Path(Path().absolute()).joinpath('app', 'swagger', 'swagger.yaml')
with open(yaml_file_path, 'r') as stream:
......
......@@ -89,7 +89,6 @@ paths:
description: "successful operation"
schema:
$ref: "#/definitions/SubmissionResponse"
x-swagger-router-controller: "swagger_server.controllers.pet_controller"
securityDefinitions:
petstore_auth:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment