FIX processqueue (sync workers still won't work)

This commit is contained in:
boyska 2014-03-27 16:31:22 +01:00
parent 2bd2f5813b
commit 98626b6099
2 changed files with 18 additions and 8 deletions

View file

@ -2,8 +2,16 @@ HOST = 'localhost'
PORT = '8000' PORT = '8000'
WSGI_SERVER = 'wsgiref' WSGI_SERVER = 'wsgiref'
WSGI_SERVER_OPTIONS = {} WSGI_SERVER_OPTIONS = {}
WSGI_SERVER = 'gunicorn' ### Beware: we use global objects (the processqueue); you can't use
WSGI_SERVER_OPTIONS = {'workers': 4 } ### 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 DEBUG = True
DB_URI = 'sqlite:///techrec.db' DB_URI = 'sqlite:///techrec.db'

View file

@ -69,9 +69,10 @@ class DateApp(Bottle):
class RecAPI(Bottle): class RecAPI(Bottle):
def __init__(self): def __init__(self, app):
Bottle.__init__(self) Bottle.__init__(self)
self._route() self._route()
self._app = app
self.db = RecDB(get_config()['DB_URI']) self.db = RecDB(get_config()['DB_URI'])
def _route(self): def _route(self):
@ -164,7 +165,7 @@ class RecAPI(Bottle):
'name': filter(lambda c: c.isalpha(), rec.name) 'name': filter(lambda c: c.isalpha(), rec.name)
} }
self.db.update(rec.id, rec.serialize()) self.db.update(rec.id, rec.serialize())
job_id = get_process_queue().submit( job_id = self._app.pq.submit(
create_mp3, create_mp3,
start=rec.starttime, start=rec.starttime,
end=rec.endtime, end=rec.endtime,
@ -177,7 +178,7 @@ class RecAPI(Bottle):
def check_job(self, job_id): def check_job(self, job_id):
try: try:
job = get_process_queue().check_job(job_id) job = self._app.pq.check_job(job_id)
except ValueError: except ValueError:
abort(400, 'job_id not valid') abort(400, 'job_id not valid')
@ -200,8 +201,8 @@ class RecAPI(Bottle):
def running_jobs(self): def running_jobs(self):
res = {} res = {}
res['last_job_id'] = get_process_queue().last_job_id res['last_job_id'] = self._app.pq.last_job_id
res['running'] = get_process_queue().jobs.keys() res['running'] = self._app.pq.jobs.keys()
return res return res
def search(self, args=None): def search(self, args=None):
@ -253,6 +254,7 @@ class RecAPI(Bottle):
class RecServer: class RecServer:
def __init__(self): def __init__(self):
self._app = Bottle() self._app = Bottle()
self._app.pq = get_process_queue()
self._route() self._route()
self.db = RecDB(get_config()['DB_URI']) self.db = RecDB(get_config()['DB_URI'])
@ -318,7 +320,7 @@ def main_cmd(*args):
"""meant to be called from argparse""" """meant to be called from argparse"""
c = RecServer() c = RecServer()
c._app.mount('/date', DateApp()) c._app.mount('/date', DateApp())
c._app.mount('/api', RecAPI()) c._app.mount('/api', RecAPI(c._app))
if get_config()['DEBUG']: if get_config()['DEBUG']:
c._app.mount('/debug', DebugAPI()) c._app.mount('/debug', DebugAPI())