Updates to create job to handle scheduling

- If the job JSON contains a scheduling date then the new 'job_status" column is set to "scheduled"
- the date is persisted on the JOB row in the database
- Also the job WILL NOT be placed onto the queue of jobs. This is deferred to a later celery beat task.
This commit is contained in:
Martyn Inglis
2016-08-24 16:00:21 +01:00
parent cf3c14dbbd
commit 10f499805c
4 changed files with 152 additions and 34 deletions
+11 -1
View File
@@ -27,6 +27,8 @@ from app.schemas import (
from app.celery.tasks import process_job
from app.models import JOB_STATUS_SCHEDULED, JOB_STATUS_PENDING
from app.utils import pagination_links
job = Blueprint('job', __name__, url_prefix='/service/<uuid:service_id>/job')
@@ -105,7 +107,15 @@ def create_job(service_id):
raise InvalidRequest(errors, status_code=400)
data.update({"template_version": template.version})
job = job_schema.load(data).data
if job.scheduled_for:
job.job_status = JOB_STATUS_SCHEDULED
dao_create_job(job)
process_job.apply_async([str(job.id)], queue="process-job")
if job.job_status == JOB_STATUS_PENDING:
process_job.apply_async([str(job.id)], queue="process-job")
return jsonify(data=job_schema.dump(job).data), 201