mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-12-25 19:04:18 +00:00
54 lines
1.9 KiB
Python
54 lines
1.9 KiB
Python
from .models import Job, User
|
|
from . import db
|
|
import logging
|
|
|
|
|
|
'''
|
|
' A list of background process functions. Functions should be called using the
|
|
Thread class from the module threading.
|
|
'''
|
|
|
|
|
|
def background_delete_user(app, current_user_id):
|
|
with app.app_context():
|
|
logger = logging.getLogger(__name__)
|
|
logger.warning('Called by delete_thread.')
|
|
logger.warning('User id is: {}.'.format(current_user_id))
|
|
jobs = Job.query.filter_by(user_id=current_user_id).all()
|
|
logger.warning('Jobs to delete are: {}'.format(jobs))
|
|
user = User.query.get_or_404(current_user_id)
|
|
for job in jobs:
|
|
job.flag_for_stop()
|
|
logger.warning('Job status: {}'.format(job.status))
|
|
deleted = False
|
|
while deleted is False:
|
|
logger.warning('Refreshing')
|
|
db.session.refresh(job)
|
|
logger.warning('Refreshed')
|
|
if job.status == 'deleted':
|
|
logger.warning('Job status is deleted.')
|
|
job.delete_job()
|
|
deleted = True
|
|
logger.warning('Loop has ended.')
|
|
user.delete_user()
|
|
|
|
|
|
def background_delete_job(app, job_id):
|
|
logger = logging.getLogger(__name__)
|
|
with app.app_context():
|
|
logger.warning('Called by delete_thread.')
|
|
logger.warning('Job id is: {}.'.format(job_id))
|
|
job = Job.query.filter_by(id=job_id).first()
|
|
logger.warning('Job object is: {}'.format(job))
|
|
logger.warning('Job status: {}'.format(job.status))
|
|
job.flag_for_stop()
|
|
logger.warning('Job status: {}'.format(job.status))
|
|
deleted = False
|
|
while deleted is False:
|
|
db.session.refresh(job)
|
|
if job.status == 'deleted':
|
|
logger.warning('Job status is deleted.')
|
|
job.delete_job()
|
|
deleted = True
|
|
logger.warning('Loop has ended.')
|