Skip to content

Commit

Permalink
[#2876] Update config changes on all instances
Browse files Browse the repository at this point in the history
  • Loading branch information
tobes committed Aug 20, 2012
1 parent a72ec6e commit af1fd51
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
17 changes: 17 additions & 0 deletions ckan/lib/app_globals.py
@@ -1,6 +1,8 @@
''' The application's Globals object '''

import logging
import time
from threading import Lock

from paste.deploy.converters import asbool
from pylons import config
Expand Down Expand Up @@ -46,6 +48,7 @@ def set_global(key, value):
''' helper function for getting value from database or config file '''
model.set_system_info(key, value)
setattr(app_globals, get_globals_key(key), value)
model.set_system_info('ckan.config_update', str(time.time()))
# update the config
config[key] = value
log.info('config `%s` set to `%s`' % (key, value))
Expand Down Expand Up @@ -106,6 +109,8 @@ def get_config_value(key, default=''):
app_globals.header_class = 'header-text-logo-tagline'




class _Globals(object):

''' Globals acts as a container for objects available throughout the
Expand All @@ -117,6 +122,18 @@ def __init__(self):
'app_globals' variable
'''
self._init()
self._config_update = None
self._mutex = Lock()

def _check_uptodate(self):
''' check the config is uptodate needed when several instances are
running '''
value = model.get_system_info('ckan.config_update')
if self._config_update != value:
if self._mutex.acquire(False):
reset()
self._config_update = value
self._mutex.release()

def _init(self):
self.favicon = config.get('ckan.favicon', '/images/icons/ckan.ico')
Expand Down
2 changes: 2 additions & 0 deletions ckan/lib/base.py
Expand Up @@ -28,6 +28,7 @@
from ckan.lib import i18n
import lib.render
import ckan.lib.helpers as h
import ckan.lib.app_globals as app_globals
from ckan.plugins import PluginImplementations, IGenshiStreamFilter
from ckan.lib.helpers import json
import ckan.model as model
Expand Down Expand Up @@ -204,6 +205,7 @@ class BaseController(WSGIController):
def __before__(self, action, **params):
c.__timer = time.time()
c.__version__ = ckan.__version__
app_globals.app_globals._check_uptodate()
self._identify_user()
i18n.handle_request(request, c)

Expand Down

0 comments on commit af1fd51

Please sign in to comment.