mirror of
https://github.com/YunoHost/yunorunner.git
synced 2024-09-03 20:05:52 +02:00
[enh] new api end point to delete a job
This commit is contained in:
parent
04cb5f0ec1
commit
dbc68a4e04
1 changed files with 22 additions and 0 deletions
22
run.py
22
run.py
|
@ -410,6 +410,28 @@ async def api_list_job(request):
|
||||||
return response.json([model_to_dict(x) for x in query.order_by(-Job.id)])
|
return response.json([model_to_dict(x) for x in query.order_by(-Job.id)])
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/api/job/<job_id:int>", methods=['DELETE'])
|
||||||
|
@require_token()
|
||||||
|
async def api_delete_job(request, job_id):
|
||||||
|
# need to stop a job before deleting it
|
||||||
|
await api_stop_job(request, job_id)
|
||||||
|
|
||||||
|
# no need to check if job exist, api_stop_job will do it for us
|
||||||
|
job = Job.select().where(Job.id == job_id)[0]
|
||||||
|
|
||||||
|
api_logger.info(f"Request to delete job '{job.name}' [{job.id}]")
|
||||||
|
|
||||||
|
data = model_to_dict(job)
|
||||||
|
job.delete_instance()
|
||||||
|
|
||||||
|
await broadcast({
|
||||||
|
"action": "delete_job",
|
||||||
|
"data": data,
|
||||||
|
}, "jobs")
|
||||||
|
|
||||||
|
return response.text("ok")
|
||||||
|
|
||||||
|
|
||||||
@app.route("/api/job/<job_id>/stop", methods=['POST'])
|
@app.route("/api/job/<job_id>/stop", methods=['POST'])
|
||||||
async def api_stop_job(request, job_id):
|
async def api_stop_job(request, job_id):
|
||||||
# TODO auth or some kind
|
# TODO auth or some kind
|
||||||
|
|
Loading…
Add table
Reference in a new issue