Commit 587def1a authored by David Mendez's avatar David Mendez
Browse files

Make Delayed Jobs type to be a foregin key in jobs config

parent 3925d549
......@@ -7,6 +7,7 @@ from flask_cors import CORS
from app.config import RUN_CONFIG
from app.config import RunEnvs
from app.db import DB
from app.models import delayed_job_models
from app.blueprints.swagger_description.swagger_description_blueprint import SWAGGER_BLUEPRINT
from app.blueprints.job_submission.controllers.job_submissions_controller import SUBMISSION_BLUEPRINT
from app.blueprints.job_status.job_status_controller import JOB_STATUS_BLUEPRINT
......@@ -35,6 +36,11 @@ def create_app():
if create_tables:
DB.create_all()
generate_default_config = RUN_CONFIG.get('generate_default_config', False)
if generate_default_config:
delayed_job_models.generate_default_job_configs()
base_path = RUN_CONFIG.get('base_path', '')
flask_app.register_blueprint(SWAGGER_BLUEPRINT, url_prefix=f'{base_path}/swagger')
......
......@@ -11,6 +11,6 @@ SUBMISSION_BLUEPRINT = Blueprint('job_submission', __name__)
@SUBMISSION_BLUEPRINT.route('/test_job', methods = ['POST'])
def submit_test_job():
job_type = delayed_job_models.JobTypes.TEST
job_type = 'TEST'
response = job_submission_service.parse_args_and_submit_job(job_type, request.form, request.files)
return jsonify(response)
\ No newline at end of file
......@@ -98,7 +98,7 @@ class TestJobSubmitter(unittest.TestCase):
Test that a job can be submitted
"""
with self.flask_app.app_context():
job_type = delayed_job_models.JobTypes.TEST
job_type = 'TEST'
docker_image_url = 'some_url'
input_files_desc, input_files_hashes, params = self.prepare_mock_job_args()
......
......@@ -15,24 +15,6 @@ DAYS_TO_LIVE = 7 # Days for which the results are kept
# pylint: disable=no-member,too-few-public-methods
class JobTypes(Enum):
"""
Types of delayed jobs
"""
TEST = 'TEST'
SIMILARITY = 'SIMILARITY'
SUBSTRUCTURE = 'SUBSTRUCTURE'
CONNECTIVITY = 'CONNECTIVITY'
BLAST = 'BLAST'
DOWNLOAD = 'DOWNLOAD'
def __repr__(self):
return self.name
def __str__(self):
return self.name
class JobStatuses(Enum):
"""
Possible statuses of delayed jobs
......@@ -61,7 +43,7 @@ class DefaultJobConfig(DB.Model):
"""
Class that represents a default container image for a job type
"""
job_type = DB.Column(DB.Enum(JobTypes), primary_key=True)
job_type = DB.Column(DB.String(length=60), primary_key=True)
docker_image_url = DB.Column(DB.Text)
......@@ -89,7 +71,7 @@ class DelayedJob(DB.Model):
Class that represents a delayed job in the database.
"""
id = DB.Column(DB.String(length=60), primary_key=True)
type = DB.Column(DB.Enum(JobTypes))
type = DB.Column(DB.String(length=60), DB.ForeignKey('default_job_config.id'), nullable=False)
status = DB.Column(DB.Enum(JobStatuses), default=JobStatuses.CREATED)
status_log = DB.Column(DB.Text) # a comment about the status, for example 'Compressing file'
progress = DB.Column(DB.Integer, default=0)
......@@ -209,6 +191,17 @@ def get_job_by_id(job_id):
raise JobNotFoundError()
return job
def generate_default_job_configs():
"""
Generates a default set of job configurations, useful for testing.
"""
test_job_config = DefaultJobConfig(
job_type='TEST',
docker_image_url='docker://dockerhub.ebi.ac.uk/chembl/chembl/delayed-jobs/test-job:8d8ea512-17-Feb-2020--10-43-54'
)
DB.session.add(test_job_config)
DB.session.commit()
def get_docker_image_url(job_type):
"""
:param job_type: job type for which to get the image url
......
run_env: DEV # DEV, TEST, STAGING or PROD
server_secret_key: 'ServerKey'
sql_alchemy:
create_tables: True
database_uri: 'sqlite:///:memory:'
track_modifications: False
elasticsearch:
dry_run: True
host: 'https://www.ebi.ac.uk/chembl/glados-es'
run_jobs: True
admin_username: 'admin'
admin_password: '123456'
jobs_output_dir: 'app/static/jobs_output'
jobs_run_dir: 'jobs_run'
\ No newline at end of file
......@@ -13,4 +13,5 @@ admin_password: '123456'
lsf_submission:
id_rsa_file: '~/.ssh/id_rsa'
lsf_user: 'lsf_user'
lsf_host: 'lsf_host'
\ No newline at end of file
lsf_host: 'lsf_host'
generate_default_config: True
\ No newline at end of file
......@@ -12,4 +12,5 @@ run_jobs: False # If False, do not actually run any job, useful for testing. Ass
logger: 'gunicorn.error' #Logger to use for the app logs
server_public_host: some_server:30001 # The base url for the jobs to send feedback to the server, if unset,
# it will be 0.0.0.0:5000
enable_cors: True
\ No newline at end of file
enable_cors: True
generate_default_config: True # Generates a default configuration for the jobs
\ No newline at end of file
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