Permalink
Browse files

[session] thread-safe session store and vacuuming

[firstrun] sort plugins
  • Loading branch information...
1 parent 120be2b commit 2e496dc93022a2ef6a438a132e74ddbb3ba61fa7 @Eugeny Eugeny committed Aug 13, 2011
@@ -193,7 +193,7 @@ class AppDispatcher(object):
def __init__(self, config=None):
self.config = config
self.log = config.get('log_facility')
- self.sessions = SessionStore()
+ self.sessions = SessionStore.init_safe()
def dispatcher(self, environ, start_response):
self.log.debug('Dispatching %s'%environ['PATH_INFO'])
View
@@ -50,6 +50,8 @@
import time
import Cookie
import hashlib
+from ajenti.utils import ClassProxy
+
def sha1(var):
return hashlib.sha1(str(var)).hexdigest()
@@ -120,15 +122,19 @@ def generateId():
class SessionStore(object):
""" Manages multiple session objects
- Could be made thread-safe
"""
# TODO: add session deletion/invalidation
- def __init__(self, timeout=24*60):
- # Default timeout is 24 hours
+ def __init__(self, timeout=30):
+ # Default timeout is 30 minutes
# Use internal timeout in seconds (for easier calculations)
self._timeout = timeout*60
self._store = {}
+ @staticmethod
+ def init_safe():
+ """ Create a thread-safe SessionStore """
+ return ClassProxy(SessionStore())
+
def create(self):
""" Create a new session,
you should commit session to save it for future
@@ -229,6 +235,7 @@ def _get_session(self, environ):
def __call__(self, environ, start_response):
self.start_response_origin = start_response
+ self._session_store.vacuum()
sess = self._get_session(environ)
environ['app.session'] = sess
@@ -4,6 +4,7 @@
<formbox id="frmPlugins" hidecancel="True">
<datatable id="list">
</datatable>
+ <br/>
</formbox>
</pad>
</xml>
@@ -24,7 +24,7 @@ def get_ui(self):
lst = self._mgr.available
- for k in lst:
+ for k in sorted(lst, key=lambda x:x.name):
row = self.app.inflate('firstrun:item')
row.find('name').set('text', k.name)
row.find('desc').set('text', k.description)
@@ -63,7 +63,10 @@ def on_event(self, event, params, vars=None):
for k in lst:
if vars.getvalue('install-'+k.id, '0') == '1':
- self._mgr.install(k.id)
+ try:
+ self._mgr.install(k.id)
+ except:
+ pass
ComponentManager.get().rescan()
self.app.gconfig.set('ajenti', 'firstrun', 'no')

0 comments on commit 2e496dc

Please sign in to comment.