diff --git a/run.py b/run.py index d124e3c..076d86a 100644 --- a/run.py +++ b/run.py @@ -481,6 +481,24 @@ async def api_stop_job(request, job_id): raise Exception(f"Tryed to cancel a job with an unknown state: {job.state}") +@app.route("/api/job//restart", methods=['POST']) +async def api_restart_job(request, job_id): + api_logger.info(f"Request to restart job {job_id}") + await api_stop_job(request, job_id) + + # no need to check if job existss, api_stop_job will do it for us + job = Job.select().where(Job.id == job_id)[0] + job.state = "scheduled" + job.save() + + await broadcast({ + "action": "update_job", + "data": data, + }, ["jobs", f"job-{job_id}"]) + + return response.text("ok") + + @app.route('/job/') @jinja.template('job.html') async def job(request, job_id):