2021-08-18 13:11:11 +00:00
|
|
|
from .. import db
|
2020-04-21 16:34:21 +00:00
|
|
|
from ..decorators import background
|
|
|
|
from ..models import Job
|
|
|
|
|
|
|
|
|
|
|
|
@background
|
2020-04-23 06:35:18 +00:00
|
|
|
def delete_job(job_id, *args, **kwargs):
|
2020-07-10 09:36:54 +00:00
|
|
|
with kwargs['app'].app_context():
|
2020-04-21 16:34:21 +00:00
|
|
|
job = Job.query.get(job_id)
|
|
|
|
if job is None:
|
2020-07-10 09:36:54 +00:00
|
|
|
raise Exception('Job {} not found'.format(job_id))
|
2020-04-21 16:34:21 +00:00
|
|
|
job.delete()
|
2020-07-10 09:36:54 +00:00
|
|
|
db.session.commit()
|
2020-07-09 07:42:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
@background
|
|
|
|
def restart_job(job_id, *args, **kwargs):
|
2020-07-10 09:36:54 +00:00
|
|
|
with kwargs['app'].app_context():
|
2020-07-09 07:42:30 +00:00
|
|
|
job = Job.query.get(job_id)
|
|
|
|
if job is None:
|
2020-07-10 09:36:54 +00:00
|
|
|
raise Exception('Job {} not found'.format(job_id))
|
2021-02-01 11:51:07 +00:00
|
|
|
try:
|
|
|
|
job.restart()
|
|
|
|
except Exception:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
db.session.commit()
|