def init_structure(self): """ Initialize structure manager using settings provided in configuration file. """ custom_settings = self.settings['config'] structure_settings = custom_settings.get('structure', {}) # detect and apply database storage module storage_module = structure_settings.get( 'storage', 'centrifuge.structure.sqlite' ) storage = utils.import_module(storage_module) structure = Structure(self) structure.set_storage(storage) self.structure = structure def run_periodic_structure_update(): structure.update() periodic_structure_update = tornado.ioloop.PeriodicCallback( structure.update, structure_settings.get('update_interval', 30)*1000 ) periodic_structure_update.start() tornado.ioloop.IOLoop.instance().add_callback( partial( storage.init_storage, structure, structure_settings.get('settings', {}), run_periodic_structure_update ) ) logger.info("Storage module: {0}".format(storage_module))
def init_structure(self): """ Initialize structure manager using settings provided in configuration file. """ custom_settings = self.settings['config'] self.structure = Structure(self) self.structure.set_storage(self.storage) def run_periodic_structure_update(): # update structure periodically from database. This is necessary to be sure # that application has actual and correct structure information. Structure # updates also triggered in real-time by message passing through control channel, # but in rare cases those update messages can be lost because of some kind of # network errors logger.info("Structure initialized") self.structure.update() structure_update_interval = custom_settings.get( 'structure_update_interval', 60) logger.info( "Periodic structure update interval: {0} seconds".format( structure_update_interval)) periodic_structure_update = tornado.ioloop.PeriodicCallback( self.structure.update, structure_update_interval * 1000) periodic_structure_update.start() tornado.ioloop.IOLoop.instance().add_callback( partial(self.storage.connect, run_periodic_structure_update))