From f1d9623d8bf8c23013aed060cf77042234708e76 Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Mon, 3 Sep 2018 06:58:50 +0200 Subject: [PATCH] [enh] new api entry point to restart a job --- run.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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):