Commit 18d0c152 authored by Julien Cigar's avatar Julien Cigar 🤘
Browse files

attach session to request, release session in plugin

parent 54b9fa94
......@@ -48,6 +48,7 @@ class SAEnginePlugin(plugins.SimplePlugin):
self.config = config
self.bus.subscribe('get-session', self.get_session)
self.bus.subscribe('release-session', self.release_session)
def start(self):
self.bus.log('SAEnginePlugin: Starting up DB access')
......@@ -95,4 +96,7 @@ class SAEnginePlugin(plugins.SimplePlugin):
self.sa_engine = None
def get_session(self):
return self.sa_session
return self.sa_session()
def release_session(self):
self.sa_session.remove()
......@@ -10,7 +10,6 @@ class SATool(cherrypy.Tool):
def __init__(self):
super(SATool, self).__init__('on_start_resource', self.bind_session,
priority=20)
self.session = None
def _setup(self):
super(SATool, self)._setup()
......@@ -18,11 +17,8 @@ class SATool(cherrypy.Tool):
self.remove_session, priority=80)
def bind_session(self):
self.session = cherrypy.engine.publish('get-session').pop()
cherrypy.request.db = cherrypy.engine.publish('get-session')
def remove_session(self):
if not self.session:
return
self.session.remove()
self.session = None
cherrypy.request.db = None
cherrypy.engine.publish('release-session')
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment