From 52b8f209315fe4f593422f968a44d4d0796a5a66 Mon Sep 17 00:00:00 2001 From: Cannon Lock <49032265+CannonLock@users.noreply.github.com> Date: Fri, 26 Aug 2022 15:51:21 -0500 Subject: [PATCH] Use ID if provided (#40) On job submissions check if a job is posted with an id, and if it is use the id for the job. --- src/server/app.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/server/app.py b/src/server/app.py index 98442b6..3c984ff 100644 --- a/src/server/app.py +++ b/src/server/app.py @@ -53,11 +53,15 @@ def _post_generic(work, request, job_timeout = 43200): # NOTE: the max amount of time a job is allowed to take is 12 hrs by default json_data = request.get_json(request.data) - + if not _authenticate(request): return 'Invalid password. do request.post(..., auth=(\'username\', \'password\'))', 401 - job = _q.enqueue(work, json_data, job_timeout = job_timeout) + # If the job is posted with an id lets use it + if 'id' in json_data: + job = _q.enqueue(work, json_data, job_timeout=job_timeout, job_id=json_data['id']) + else: + job = _q.enqueue(work, json_data, job_timeout=job_timeout) job_data = dict() job_data['id'] = job.id @@ -81,7 +85,7 @@ def _get_generic(request): if 'progress' in meta: job_data['progress'] = meta['progress'] - + if job.result is not None: job_data['result'] = job.result status_code = 200