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

use transactions

parent a9219680358a
...@@ -189,7 +189,7 @@ def reworkui(engine, ...@@ -189,7 +189,7 @@ def reworkui(engine,
@bp.route('/list_jobs') @bp.route('/list_jobs')
def list_jobs(): def list_jobs():
with engine.connect() as cn: with engine.begin() as cn:
tsql = 'select id from rework.task order by id' tsql = 'select id from rework.task order by id'
jobids = cn.execute(tsql).fetchall() jobids = cn.execute(tsql).fetchall()
opsql = 'select id, name from rework.operation' opsql = 'select id, name from rework.operation'
...@@ -210,14 +210,14 @@ def reworkui(engine, ...@@ -210,14 +210,14 @@ def reworkui(engine,
@bp.route('/shutdown-worker/<wid>') @bp.route('/shutdown-worker/<wid>')
def shutdown_worker(wid): def shutdown_worker(wid):
with engine.connect() as cn: with engine.begin() as cn:
cn.execute(worker.update().where(worker.c.id == wid cn.execute(worker.update().where(worker.c.id == wid
).values(shutdown=True)) ).values(shutdown=True))
return json.dumps(True) return json.dumps(True)
@bp.route('/kill-worker/<wid>') @bp.route('/kill-worker/<wid>')
def kill_worker(wid): def kill_worker(wid):
with engine.connect() as cn: with engine.begin() as cn:
cn.execute(worker.update().where(worker.c.id == wid cn.execute(worker.update().where(worker.c.id == wid
).values(kill=True)) ).values(kill=True))
return json.dumps(True) return json.dumps(True)
...@@ -308,14 +308,14 @@ def reworkui(engine, ...@@ -308,14 +308,14 @@ def reworkui(engine,
@bp.route('/delete-task/<tid>') @bp.route('/delete-task/<tid>')
def delete_task(tid): def delete_task(tid):
with engine.connect() as cn: with engine.begin() as cn:
cn.execute("delete from rework.task where id = %(tid)s and status != 'running'", cn.execute("delete from rework.task where id = %(tid)s and status != 'running'",
tid=tid) tid=tid)
return json.dumps(True) return json.dumps(True)
@bp.route('/abort-task/<tid>') @bp.route('/abort-task/<tid>')
def abort_task(tid): def abort_task(tid):
with engine.connect() as cn: with engine.begin() as cn:
sql = task.update().where(task.c.id == tid sql = task.update().where(task.c.id == tid
).values(abort=True) ).values(abort=True)
cn.execute(sql) cn.execute(sql)
......
...@@ -14,10 +14,10 @@ taskstable = Table( ...@@ -14,10 +14,10 @@ taskstable = Table(
def init(engine): def init(engine):
with engine.connect() as cn: with engine.begin() as cn:
taskstable.create(cn) taskstable.create(cn)
def reset(engine): def reset(engine):
with engine.connect() as cn: with engine.begin() as cn:
taskstable.drop(cn, checkfirst=True) taskstable.drop(cn, checkfirst=True)
...@@ -35,7 +35,7 @@ def refresh_tasks(engine, inithash, domain): ...@@ -35,7 +35,7 @@ def refresh_tasks(engine, inithash, domain):
domain=domain, domain=domain,
content=htmltable content=htmltable
) )
with engine.connect() as cn: with engine.begin() as cn:
cn.execute(sql) cn.execute(sql)
inithash = thash inithash = thash
# cleanup old tables # cleanup old tables
...@@ -44,7 +44,7 @@ def refresh_tasks(engine, inithash, domain): ...@@ -44,7 +44,7 @@ def refresh_tasks(engine, inithash, domain):
).where( ).where(
taskstable.c.domain == domain taskstable.c.domain == domain
) )
with engine.connect() as cn: with engine.begin() as cn:
cn.execute(sql) cn.execute(sql)
return inithash return inithash
...@@ -75,7 +75,7 @@ def refresh_tasks_file(engine, loop=False, sleeptime=2): ...@@ -75,7 +75,7 @@ def refresh_tasks_file(engine, loop=False, sleeptime=2):
def tasks_info(engine, domain): def tasks_info(engine, domain):
with engine.connect() as cn: with engine.begin() as cn:
sql = select( sql = select(
[task.c.id, task.c.status, operation.c.domain] [task.c.id, task.c.status, operation.c.domain]
).order_by(desc(task.c.id) ).order_by(desc(task.c.id)
......
...@@ -126,7 +126,7 @@ def test_task_life_cycle(engine, client, refresh): ...@@ -126,7 +126,7 @@ def test_task_life_cycle(engine, client, refresh):
def test_tasks_table(engine, client, refresh): def test_tasks_table(engine, client, refresh):
with engine.connect() as cn: with engine.begin() as cn:
cn.execute('delete from rework.task') cn.execute('delete from rework.task')
with workers(engine): with workers(engine):
......
Markdown is supported
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