Esempio n. 1
0
def engine_uri(database=None):
    """ By default doesn't include the specific database. """

    config_prefix = 'RDS' if is_prod() else 'MYSQL'

    username = config.get('{0}_USER'.format(config_prefix), None)
    assert username, "Must have database username to connect!"

    password = config.get('{0}_PASSWORD'.format(config_prefix), None)
    assert password, "Must have database password to connect!"

    host = config.get('{0}_HOSTNAME'.format(config_prefix), None)
    assert host, "Must have database to connect!"

    port = config.get('{0}_PORT'.format(config_prefix), None)
    assert port, "Must have database port to connect!"

    uri_template = 'mysql://{username}:{password}@{host}:{port}/{database}?charset=utf8mb4'

    return uri_template.format(
        username=username,
        # http://stackoverflow.com/questions/15728290/sqlalchemy-valueerror-for-slash-in-password-for-create-engine (also applicable to '+' sign)
        password=urlquote(password),
        host=host,
        port=port,
        database=database if database else '')
Esempio n. 2
0
 def __call__(self, *args, **kwargs):
     from inbox.server.config import is_prod, is_staging
     func = self.func
     try:
         return func(*args, **kwargs)
     except Exception, e:
         if not isinstance(e, GreenletExit):
             self._log_failsafe("Uncaught error!")
             exc_type, exc_value, exc_tb = sys.exc_info()
             if is_prod() or is_staging():
                 email_exception(self.logger, exc_type, exc_value, exc_tb)
         raise
Esempio n. 3
0
File: log.py Progetto: caitp/inbox
 def __call__(self, *args, **kwargs):
     from inbox.server.config import is_prod, is_staging
     func = self.func
     try:
         return func(*args, **kwargs)
     except Exception, e:
         if not isinstance(e, GreenletExit):
             self._log_failsafe("Uncaught error!")
             exc_type, exc_value, exc_tb = sys.exc_info()
             if is_prod() or is_staging():
                 email_exception(self.logger, exc_type, exc_value, exc_tb)
         raise
Esempio n. 4
0
def db_uri():
    config_prefix = 'RDS' if is_prod() else 'MYSQL'
    database = config.get('{0}_DATABASE'.format(config_prefix), None)
    assert database, "Must have database name to connect!"
    return engine_uri(database)