class AggregatorApplication(object): """Base application """ def __init__(self, config): self.config = config self.data_processor = None self.status_processor = None self.tasks = Tasks() self.backends = [] self.start_time = time.time() self.cache = Cache() def configure_app(self, io_loop=None): """Configure application backends and storages """ storage = self.configure_storage(self.config['STORAGE']) self.configure_backends(self.config['BACKENDS'], io_loop, self.config, storage, self.tasks) # Add periodic processing self.data_processor = PeriodicProcessor(self, io_loop=io_loop) self.data_processor.start() self.status_processor = StatusPeriodicCallback(self, io_loop=io_loop) self.status_processor.start() def add_task(self, f, *args, **kwargs): """Add new task to tasks deque :param task_type: task type (incr, decr) :param data: (type parameters) """ self.tasks.append((f, args, kwargs)) def summary(self): logger.info("Aggregator running {0}".format(pretty_timedelta(time.time() - self.start_time))) for backend in self.backends: backend.log_backend_status() self.data_processor.summary() self.storage.get_status() def configure_storage(self, storage_path): """Configure data storage by path :param storage: storage path """ module_path, name = storage_path.rsplit('.', 1) try: module = importlib.import_module(module_path, name) storage = getattr(module, name) except (ImportError, AttributeError), e: raise Exception("Invalid storage: {0}".format(e)) return storage.setup(self)
def __init__(self, config): self.config = config self.data_processor = None self.status_processor = None self.tasks = Tasks() self.backends = [] self.start_time = time.time() self.cache = Cache()
def __init__(self, config): self.config = config self.data_processor = None self.status_processor = None self.tasks = Tasks() self.backends = [] self.start_time = time.time() self.cache = Cache() tornado.web.Application.__init__(self, [], **config)