nopaque/app/jobs/tasks.py

28 lines
678 B
Python
Raw Normal View History

from app import db
from app.decorators import background
from app.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:
2021-12-08 13:45:05 +00:00
raise Exception(f'Job {job_id} not found')
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:
2021-12-08 13:45:05 +00:00
raise Exception(f'Job {job_id} not found')
try:
job.restart()
except Exception:
pass
else:
db.session.commit()