From 31d0588a35c8df17a5d3adcfc25af2b72c896cc7 Mon Sep 17 00:00:00 2001 From: schneefux Date: Sun, 26 Feb 2017 18:32:14 +0100 Subject: add job fails (#4) --- joblib.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'joblib.py') diff --git a/joblib.py b/joblib.py index a0ce985..48666a6 100644 --- a/joblib.py +++ b/joblib.py @@ -78,6 +78,21 @@ class JobQueue(object): except asyncpg.exceptions.SerializationError: pass + async def fail(self, jobid, reason): + """Mark a job as failed.""" + async with self._pool.acquire() as con: + while True: + try: + async with con.transaction(isolation="serializable"): + await con.execute(""" + UPDATE jobs + SET status='failed', payload=payload||$2::jsonb + WHERE id=$1 + """, jobid, json.dumps({"error": reason})) + return + except asyncpg.exceptions.SerializationError: + pass + async def cleanup(self): """Reopen all unfinished jobs.""" async with self._pool.acquire() as con: -- cgit v1.3.1