From 338e4111c2acf17e553844acb54819dae35e5f91 Mon Sep 17 00:00:00 2001 From: Patrick Jentsch <p.jentsch@uni-bielefeld.de> Date: Tue, 6 Aug 2019 14:54:00 +0200 Subject: [PATCH] Add user id to path. --- app/services/views.py | 14 +++++++++----- app/swarm.py | 13 ++++++++----- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/app/services/views.py b/app/services/views.py index c3be8ac5..33b3fa06 100644 --- a/app/services/views.py +++ b/app/services/views.py @@ -34,7 +34,10 @@ def ocr(): db.session.add(ocr_job) db.session.commit() - dir = os.path.join(app.config['OPAQUE_STORAGE'], 'jobs', str(ocr_job.id)) + dir = os.path.join(app.config['OPAQUE_STORAGE'], + str(ocr_job.user_id), + 'jobs', + str(ocr_job.id)) try: os.makedirs(dir) @@ -67,9 +70,6 @@ def nlp(): new_nlp_job_form = NewNLPJobForm() if new_nlp_job_form.validate_on_submit(): app = current_app._get_current_object() - id = hashlib.md5( - (current_user.username + '_' + datetime.now().isoformat()).encode() - ).hexdigest() nlp_job = Job() nlp_job.title = new_nlp_job_form.title.data nlp_job.description = new_nlp_job_form.description.data @@ -84,7 +84,11 @@ def nlp(): nlp_job.status = "queued" db.session.add(nlp_job) db.session.commit() - dir = os.path.join(app.config['OPAQUE_STORAGE'], 'jobs', str(nlp_job.id)) + + dir = os.path.join(app.config['OPAQUE_STORAGE'], + str(nlp_job.user_id), + 'jobs', + str(nlp_job.id)) try: os.makedirs(dir) diff --git a/app/swarm.py b/app/swarm.py index 859a9f91..32e0d269 100644 --- a/app/swarm.py +++ b/app/swarm.py @@ -1,6 +1,7 @@ import docker import time import json +import os class Swarm: @@ -27,9 +28,9 @@ class Swarm: service_args = json.loads(job.service_args) ressources = json.loads(job.ressources) _command = (job.service - + ' -i /files/{}'.format(job.id) + + ' -i /files' + ' -l {}'.format(service_args['lang']) - + ' -o /files/{}/output'.format(job.id) + + ' -o /files/output' + ' ' + ' '.join(service_args['args'])) _constraints = ['node.role==worker'] _image = 'gitlab.ub.uni-bielefeld.de:4567/sfb1288inf/{}:{}'.format( @@ -37,9 +38,11 @@ class Swarm: service_args['version'] ) _labels = {'service': job.service} - _mounts = [ - '/home/compute/mnt/opaque/jobs:/files:rw', - ] + _mounts = [os.path.join('/home/compute/mnt/opaque', + str(job.user_id), + 'jobs', + str(job.id)) + + ':/files:rw'] _name = job.id ''' ' The Docker SDK for Python expects the cpu_reservation value to be -- GitLab