nopaque/web/app/jobs/tasks.py

24 lines
611 B
Python
Raw Normal View History

2020-07-10 09:36:54 +00:00
from .. import db
from ..decorators import background
from ..models import Job
@background
def delete_job(job_id, *args, **kwargs):
2020-07-10 09:36:54 +00:00
with kwargs['app'].app_context():
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))
job.delete()
2020-07-10 09:36:54 +00:00
db.session.commit()
@background
def restart_job(job_id, *args, **kwargs):
2020-07-10 09:36:54 +00:00
with kwargs['app'].app_context():
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))
job.restart()
2020-07-10 09:36:54 +00:00
db.session.commit()