From 98626b60996d55ec91bf7f97a2426cb88a5d8b61 Mon Sep 17 00:00:00 2001 From: boyska Date: Thu, 27 Mar 2014 16:31:22 +0100 Subject: [PATCH] FIX processqueue (sync workers still won't work) --- server/default_config.py | 12 ++++++++++-- server/server.py | 14 ++++++++------ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/server/default_config.py b/server/default_config.py index 9c87595..54567a0 100644 --- a/server/default_config.py +++ b/server/default_config.py @@ -2,8 +2,16 @@ HOST = 'localhost' PORT = '8000' WSGI_SERVER = 'wsgiref' WSGI_SERVER_OPTIONS = {} -WSGI_SERVER = 'gunicorn' -WSGI_SERVER_OPTIONS = {'workers': 4 } +### Beware: we use global objects (the processqueue); you can't use +### worker_class=sync in gunicorn, and probably other similar deployment won't +### work +### A dirty check is: +### * go to /old.html +### * create something +### * go to /api/jobs +### * refresh a lot and see if the result is always the same +#WSGI_SERVER = 'gunicorn' +#WSGI_SERVER_OPTIONS = {'workers': 4, 'worker_class': 'eventlet' } DEBUG = True DB_URI = 'sqlite:///techrec.db' diff --git a/server/server.py b/server/server.py index 5fc7d11..e15bbcd 100644 --- a/server/server.py +++ b/server/server.py @@ -69,9 +69,10 @@ class DateApp(Bottle): class RecAPI(Bottle): - def __init__(self): + def __init__(self, app): Bottle.__init__(self) self._route() + self._app = app self.db = RecDB(get_config()['DB_URI']) def _route(self): @@ -164,7 +165,7 @@ class RecAPI(Bottle): 'name': filter(lambda c: c.isalpha(), rec.name) } self.db.update(rec.id, rec.serialize()) - job_id = get_process_queue().submit( + job_id = self._app.pq.submit( create_mp3, start=rec.starttime, end=rec.endtime, @@ -177,7 +178,7 @@ class RecAPI(Bottle): def check_job(self, job_id): try: - job = get_process_queue().check_job(job_id) + job = self._app.pq.check_job(job_id) except ValueError: abort(400, 'job_id not valid') @@ -200,8 +201,8 @@ class RecAPI(Bottle): def running_jobs(self): res = {} - res['last_job_id'] = get_process_queue().last_job_id - res['running'] = get_process_queue().jobs.keys() + res['last_job_id'] = self._app.pq.last_job_id + res['running'] = self._app.pq.jobs.keys() return res def search(self, args=None): @@ -253,6 +254,7 @@ class RecAPI(Bottle): class RecServer: def __init__(self): self._app = Bottle() + self._app.pq = get_process_queue() self._route() self.db = RecDB(get_config()['DB_URI']) @@ -318,7 +320,7 @@ def main_cmd(*args): """meant to be called from argparse""" c = RecServer() c._app.mount('/date', DateApp()) - c._app.mount('/api', RecAPI()) + c._app.mount('/api', RecAPI(c._app)) if get_config()['DEBUG']: c._app.mount('/debug', DebugAPI())