Commit 3043bbb7 authored by Aurélien Campéas's avatar Aurélien Campéas
Browse files

blueprint: fix task abortion

This is why open-coded sql is a bad idea ...
The Task.abort method does what is needed.
parent 6708fad6ef67
......@@ -174,19 +174,6 @@ def reworkui(engine,
logs = job.logs(fromid=args.from_log_id)
return json.dumps([[lid, line] for lid, line in logs])
def kill_job(jobid):
job = getjob(engine, jobid)
if job is None:
abort(404, 'NO SUCH JOB')
if job.aborted:
return 'was already aborted'
return 'job terminated'
def list_jobs():
with engine.begin() as cn:
......@@ -315,10 +302,14 @@ def reworkui(engine,
def abort_task(tid):
with engine.begin() as cn:
sql = task.update().where( == tid
t = Task.byid(engine, tid)
if t is None:
abort(404, 'NO SUCH JOB')
if t.aborted:
return json.dumps(False)
return json.dumps(True)
......@@ -10,6 +10,13 @@
<td scope="row">3</td>
<td scope="row">2</td>
import re
from pathlib import Path
import time
from lxml import etree
......@@ -38,6 +39,14 @@ def bad_job(task):
raise Exception('I am a little crasher.')
def abortme(task):
while True:
# tests
def test_no_job(client):
res = client.get('/job_status/babar')
assert res.status_code == 404
......@@ -65,6 +74,18 @@ def test_bad_request(engine, client):
assert b'input file is mandatory' in res.body
def test_abort(engine, client):
with workers(engine) as mon:
res = client.put('/new_job/abortme?user=Babar',
upload_files=[('input_file', 'input.xml', b'the file', 'text/xml')])
tid = int(res.body)
t = Task.byid(engine, tid)
assert not t.aborted
res = client.get(f'/abort-task/{tid}')
assert t.aborted
def test_task_life_cycle(engine, client, refresh):
with workers(engine):
tasks = []
......@@ -192,7 +213,7 @@ def test_tasks_table(engine, client, refresh):
res = client.get('/tasks-table-hash?domain=uranus')
assert res.text == 'ce14320fb847e8e7443ffca102315671'
assert res.text == '98cc14b1de9bdd660aaa61f8b2ac4144'
res = client.get('/tasks-table?domain=uranus')
refpath = DATADIR / 'tasks-table-uranus.html'
if refresh:
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment