mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-12-24 18:34:18 +00:00
Create send_notification function
This commit is contained in:
parent
ddee38e2a5
commit
ba7789224b
@ -140,7 +140,8 @@ class User(UserMixin, db.Model):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def path(self):
|
def path(self):
|
||||||
return os.path.join(current_app.config['NOPAQUE_DATA_DIR'], str(self.id))
|
return os.path.join(current_app.config['NOPAQUE_DATA_DIR'],
|
||||||
|
str(self.id))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def password(self):
|
def password(self):
|
||||||
|
@ -41,13 +41,7 @@ def create_job_service(job):
|
|||||||
else:
|
else:
|
||||||
job.status = 'queued'
|
job.status = 'queued'
|
||||||
finally:
|
finally:
|
||||||
msg = create_message(
|
send_notification(job)
|
||||||
job.creator.email,
|
|
||||||
'Status update for your Job "{}"'.format(job.title),
|
|
||||||
'tasks/email/notification',
|
|
||||||
job=job
|
|
||||||
)
|
|
||||||
mail.send(msg)
|
|
||||||
|
|
||||||
|
|
||||||
def checkout_job_service(job):
|
def checkout_job_service(job):
|
||||||
@ -85,8 +79,6 @@ def checkout_job_service(job):
|
|||||||
+ 'Details: {}'.format(e))
|
+ 'Details: {}'.format(e))
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
job.end_date = datetime.utcnow()
|
|
||||||
job.status = task_state
|
|
||||||
if task_state == 'complete':
|
if task_state == 'complete':
|
||||||
job_results_dir = os.path.join(job.path, 'output')
|
job_results_dir = os.path.join(job.path, 'output')
|
||||||
job_results = filter(lambda x: x.endswith('.zip'),
|
job_results = filter(lambda x: x.endswith('.zip'),
|
||||||
@ -94,14 +86,10 @@ def checkout_job_service(job):
|
|||||||
for job_result in job_results:
|
for job_result in job_results:
|
||||||
job_result = JobResult(filename=job_result, job=job)
|
job_result = JobResult(filename=job_result, job=job)
|
||||||
db.session.add(job_result)
|
db.session.add(job_result)
|
||||||
|
job.end_date = datetime.utcnow()
|
||||||
|
job.status = task_state
|
||||||
finally:
|
finally:
|
||||||
msg = create_message(
|
send_notification(job)
|
||||||
job.creator.email,
|
|
||||||
'Status update for your Job "{}"'.format(job.title),
|
|
||||||
'tasks/email/notification',
|
|
||||||
job=job
|
|
||||||
)
|
|
||||||
mail.send(msg)
|
|
||||||
|
|
||||||
|
|
||||||
def remove_job_service(job):
|
def remove_job_service(job):
|
||||||
@ -134,3 +122,15 @@ def remove_job_service(job):
|
|||||||
logging.error('Remove "{}" service raised '.format(service_name) # noqa
|
logging.error('Remove "{}" service raised '.format(service_name) # noqa
|
||||||
+ '[docker-APIError] The server returned an error. ' # noqa
|
+ '[docker-APIError] The server returned an error. ' # noqa
|
||||||
+ 'Details: {}'.format(e))
|
+ 'Details: {}'.format(e))
|
||||||
|
|
||||||
|
|
||||||
|
def send_notification(job):
|
||||||
|
if job.creator.setting_job_status_mail_notifications == 'none':
|
||||||
|
return
|
||||||
|
if (job.creator.setting_job_status_mail_notifications == 'end'
|
||||||
|
and job.status not in ['complete', 'failed']):
|
||||||
|
return
|
||||||
|
msg = create_message(job.creator.email,
|
||||||
|
'Status update for your Job "{}"'.format(job.title),
|
||||||
|
'tasks/email/notification', job=job)
|
||||||
|
mail.send(msg)
|
||||||
|
Loading…
Reference in New Issue
Block a user