diff options
Diffstat (limited to 'gerboweb')
-rw-r--r-- | gerboweb/gerboweb.py | 17 | ||||
-rw-r--r-- | gerboweb/job_queue.py | 19 |
2 files changed, 15 insertions, 21 deletions
diff --git a/gerboweb/gerboweb.py b/gerboweb/gerboweb.py index a276d74..7e952a4 100644 --- a/gerboweb/gerboweb.py +++ b/gerboweb/gerboweb.py @@ -63,8 +63,12 @@ def index(): 'reset_form': ResetForm() } for job in ('vector_job', 'render_job'): - if job in session and job_queue[session[job]].finished: - del session[job] + if job in session: + job = job_queue[session[job]] + if job.finished: + if job.result != 0: + flash(f'Error processing gerber files', 'success') # FIXME make this an error, add CSS + del session[job] r = make_response(render_template('index.html', has_renders = path.isfile(tempfile_path('gerber.zip')), @@ -81,7 +85,7 @@ def index(): def vectorize(): if 'vector_job' in session: - job_queue.drop(session['vector_job']) + job_queue[session['vector_job']].abort() session['vector_job'] = job_queue.enqueue('vector', client=request.remote_addr, session_id=session['session_id'], @@ -89,7 +93,7 @@ def vectorize(): def render(): if 'render_job' in session: - job_queue.drop(session['render_job']) + job_queue[session['render_job']].abort() session['render_job'] = job_queue.enqueue('render', session_id=session['session_id'], client=request.remote_addr) @@ -115,6 +119,7 @@ def upload_gerber(): def upload_overlay(): upload_form = OverlayForm() if upload_form.validate_on_submit(): + # FIXME raise error when no side selected f = upload_form.upload_file.data f.save(tempfile_path('overlay.png')) session['side_selected'] = upload_form.side.data @@ -152,9 +157,9 @@ def output_download(): @require_session_id def session_reset(): if 'render_job' in session: - session['render_job'].abort() + job_queue[session['render_job']].abort() if 'vector_job' in session: - session['vector_job'].abort() + job_queue[session['vector_job']].abort() session.clear() flash('Session reset', 'success'); return redirect(url_for('index')) 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,)) |