diff options
author | jaseg <code@jaseg.net> | 2019-04-02 04:34:57 +0900 |
---|---|---|
committer | jaseg <git@jaseg.net> | 2019-04-02 04:34:57 +0900 |
commit | a846d39bc88e0c03402b20790b04762666bc055f (patch) | |
tree | 52e51d6883e0062667e15de912b362f6acf3acba /gerboweb/job_queue.py | |
parent | bd146dd1636116680f7d9a4e1a85adc3d803a7c5 (diff) | |
download | gerbolyze-a846d39bc88e0c03402b20790b04762666bc055f.tar.gz gerbolyze-a846d39bc88e0c03402b20790b04762666bc055f.tar.bz2 gerbolyze-a846d39bc88e0c03402b20790b04762666bc055f.zip |
gerboweb: Fix job queue handling
Diffstat (limited to 'gerboweb/job_queue.py')
-rw-r--r-- | gerboweb/job_queue.py | 19 |
1 files changed, 4 insertions, 15 deletions
diff --git a/gerboweb/job_queue.py b/gerboweb/job_queue.py index e48379d..76f17dc 100644 --- a/gerboweb/job_queue.py +++ b/gerboweb/job_queue.py @@ -25,22 +25,11 @@ class JobQueue: return conn.execute('INSERT INTO jobs(type, client, params) VALUES (?, ?, ?)', (task_type, client, json.dumps(params))).lastrowid - def check_result(slef, job_id): - with self.db as conn: - job = conn.execute('SELECT * FROM jobs WHERE id=?', (job_id,)).fetchone() - if job is None: - raise IndexError('Job id not found') - return job.result - - def drop(self, job_id): - with self.db as conn: - return conn.execute('DELETE FROM jobs WHERE id=?', (job_id,)).rowcount > 0 - def pop(self, task_type): """ Fetch the next job of the given type. Returns a sqlite3.Row object of the job or None if no jobs of the given type are queued. """ with self.db as conn: - job = conn.execute('SELECT * FROM jobs WHERE type=? AND consumed IS NULL ORDER BY created ASC LIMIT 1', + job = conn.execute('SELECT * FROM jobs WHERE type=? AND consumed IS NULL AND aborted IS NULL ORDER BY created ASC LIMIT 1', (task_type,)).fetchone() if job is None: return None @@ -73,7 +62,7 @@ class Job(dict): self.created = row['created'] self.consumed = row['consumed'] self.finished = row['finished'] - self.result = None + self.result = row['result'] def __enter__(self): return self @@ -82,7 +71,7 @@ class Job(dict): with self._db as conn: conn.execute('UPDATE jobs SET finished=datetime("now"), result=? WHERE id=?', (self.result, self.id,)) - def abort(self): - with self._db as conn: + def abort(self, job_id): + with self.db as conn: conn.execute('UPDATE jobs SET aborted=datetime("now") WHERE id=?', (self.id,)) |