diff --git a/app/dao/jobs_dao.py b/app/dao/jobs_dao.py index e3df928a5..9cb192af0 100644 --- a/app/dao/jobs_dao.py +++ b/app/dao/jobs_dao.py @@ -4,13 +4,13 @@ from app.models import Job def save_job(job, update_dict={}): if update_dict: - update_dict.pop('id') - update_dict.pop('service') - update_dict.pop('template') + update_dict.pop('id', None) + update_dict.pop('service', None) + update_dict.pop('template', None) Job.query.filter_by(id=job.id).update(update_dict) else: db.session.add(job) - db.session.commit() + db.session.commit() def get_job(service_id, job_id): diff --git a/app/job/rest.py b/app/job/rest.py index 5597cc181..fab9b2a8c 100644 --- a/app/job/rest.py +++ b/app/job/rest.py @@ -60,6 +60,7 @@ def create_job(service_id): @job.route('/', methods=['PUT']) def update_job(service_id, job_id): + job = get_job(service_id, job_id) update_dict, errors = job_schema_load_json.load(request.get_json()) if errors: @@ -77,14 +78,19 @@ def _enqueue_job(job): queue = boto3.resource('sqs', region_name=aws_region).create_queue(QueueName=queue_name) data = { - 'job_id': str(job.id), + 'id': str(job.id), 'service_id': str(job.service.id), - 'template_id': job.template_id, - 'bucket_name': job.bucket_name + 'template_id': job.template.id, + 'bucket_name': job.bucket_name, + 'file_name': job.file_name, + 'original_file_name': job.original_file_name } job_json = json.dumps(data) queue.send_message(MessageBody=job_json, - MessageAttributes={'job_id': {'StringValue': str(job.id), 'DataType': 'String'}, - 'service_id': {'StringValue': str(job.service.id), 'DataType': 'String'}, - 'template_id': {'StringValue': str(job.template_id), 'DataType': 'Number'}, - 'bucket_name': {'StringValue': job.bucket_name, 'DataType': 'String'}}) + MessageAttributes={'id': {'StringValue': str(job.id), 'DataType': 'String'}, + 'service': {'StringValue': str(job.service.id), 'DataType': 'String'}, + 'template': {'StringValue': str(job.template.id), 'DataType': 'String'}, + 'bucket_name': {'StringValue': job.bucket_name, 'DataType': 'String'}, + 'file_name': {'StringValue': job.file_name, 'DataType': 'String'}, + 'original_file_name': {'StringValue': job.original_file_name, + 'DataType': 'String'}}) diff --git a/tests/app/job/test_job_rest.py b/tests/app/job/test_job_rest.py index 6a7b385d8..59f8049a7 100644 --- a/tests/app/job/test_job_rest.py +++ b/tests/app/job/test_job_rest.py @@ -119,7 +119,7 @@ def test_create_job(notify_api, notify_db, notify_db_session, sample_template): assert len(messages) == 1 expected_message = json.loads(messages[0].body) - assert expected_message['job_id'] == str(job_id) + assert expected_message['id'] == str(job_id) assert expected_message['service_id'] == str(service_id) assert expected_message['template_id'] == template_id assert expected_message['bucket_name'] == bucket_name