def __init__(self): self.settings = Settings.get_instance() self._http_client = CachedClient( redis_hostname=self.settings['redis']['hostname'], cache_expires=self.settings['redis']['cache_expires']) self._max_count = 20 self._default_count = 20
import logging from peewee import * from utils.settings import Settings settings = Settings.get_instance() mysql_db = MySQLDatabase( settings['mysql']['database'], user=settings['mysql']['username'], password=settings['mysql']['password'], host=settings['mysql']['hostname'], port=settings['mysql']['hostport'] ) def mysql_query(func): def function_wrapper(*args, **kwargs): if mysql_db.is_closed(): logging.info('Opening MySQL Connection') mysql_db.connect() result = func(*args, **kwargs) if not mysql_db.is_closed(): logging.info('Closing MySQL Connection') mysql_db.close() return result return function_wrapper class BaseModel(Model): class Meta: database = mysql_db