From 9a475f2ad27a87bb27de73af09d83e275e433c06 Mon Sep 17 00:00:00 2001
From: Patrick Jentsch
Date: Mon, 18 Nov 2019 15:55:19 +0100
Subject: [PATCH] Remove job deletion workaround
---
app/models.py | 41 ++++++++++++++---------------------------
1 file changed, 14 insertions(+), 27 deletions(-)
diff --git a/app/models.py b/app/models.py
index 47cce8e9..87cd38df 100644
--- a/app/models.py
+++ b/app/models.py
@@ -2,6 +2,7 @@ from datetime import datetime
from flask import current_app
from flask_login import UserMixin, AnonymousUserMixin
from itsdangerous import BadSignature, TimedJSONWebSignatureSerializer
+from time import sleep
from werkzeug.security import generate_password_hash, check_password_hash
from . import db, logger, login_manager
import os
@@ -330,23 +331,16 @@ class Job(db.Model):
self.status = 'stopping'
db.session.commit()
while self.status != 'deleted':
- ''' TODO: wait a second '''
+ sleep(1)
db.session.refresh(self)
path = os.path.join(current_app.config['OPAQUE_STORAGE_DIRECTORY'],
str(self.user_id), 'jobs', str(self.id))
- '''
- ' TODO: Remove this workaround by executing the following command
- ' before service removal.
- '
- ' docker service update --mount-rm
- '''
- while os.path.exists(path):
- try:
- shutil.rmtree(path)
- except Exception as e:
- ''' TODO: Proper exception handling '''
- logger.warning(e)
- pass
+ try:
+ shutil.rmtree(path)
+ except Exception as e:
+ ''' TODO: Proper exception handling '''
+ logger.warning(e)
+ pass
db.session.delete(self)
db.session.commit()
@@ -445,19 +439,12 @@ class Corpus(db.Model):
corpus_file.delete()
path = os.path.join(current_app.config['OPAQUE_STORAGE_DIRECTORY'],
str(self.user_id), 'corpora', str(self.id))
- '''
- ' TODO: Remove this workaround by executing the following command
- ' before service removal.
- '
- ' docker service update --mount-rm
- '''
- while os.path.exists(path):
- try:
- shutil.rmtree(path)
- except Exception as e:
- ''' TODO: Proper exception handling '''
- logger.warning(e)
- pass
+ try:
+ shutil.rmtree(path)
+ except Exception as e:
+ ''' TODO: Proper exception handling '''
+ logger.warning(e)
+ pass
db.session.delete(self)
db.session.commit()