settings.py 2.7 KB
Newer Older
P
peng.xu 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13
import sys
import os

from environs import Env
env = Env()

FROM_EXAMPLE = env.bool('FROM_EXAMPLE', False)
if FROM_EXAMPLE:
    from dotenv import load_dotenv
    load_dotenv('./mishards/.env.example')
else:
    env.read_env()

P
peng.xu 已提交
14

P
peng.xu 已提交
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
DEBUG = env.bool('DEBUG', False)

LOG_LEVEL = env.str('LOG_LEVEL', 'DEBUG' if DEBUG else 'INFO')
LOG_PATH = env.str('LOG_PATH', '/tmp/mishards')
LOG_NAME = env.str('LOG_NAME', 'logfile')
TIMEZONE = env.str('TIMEZONE', 'UTC')

from utils.logger_helper import config
config(LOG_LEVEL, LOG_PATH, LOG_NAME, TIMEZONE)

TIMEOUT = env.int('TIMEOUT', 60)
MAX_RETRY = env.int('MAX_RETRY', 3)

SERVER_PORT = env.int('SERVER_PORT', 19530)
SERVER_TEST_PORT = env.int('SERVER_TEST_PORT', 19530)
WOSERVER = env.str('WOSERVER')

P
peng.xu 已提交
32 33
DISCOVERY_STATIC_HOSTS = env.list('DISCOVERY_STATIC_HOSTS', [])
DISCOVERY_STATIC_PORT = env.int('DISCOVERY_STATIC_PORT', 19530)
P
peng.xu 已提交
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63

# TESTING_WOSERVER = env.str('TESTING_WOSERVER', 'tcp://127.0.0.1:19530')


class TracingConfig:
    TRACING_SERVICE_NAME = env.str('TRACING_SERVICE_NAME', 'mishards')
    TRACING_VALIDATE = env.bool('TRACING_VALIDATE', True)
    TRACING_LOG_PAYLOAD = env.bool('TRACING_LOG_PAYLOAD', False)
    TRACING_CONFIG = {
        'sampler': {
            'type': env.str('TRACING_SAMPLER_TYPE', 'const'),
            'param': env.str('TRACING_SAMPLER_PARAM', "1"),
        },
        'local_agent': {
            'reporting_host': env.str('TRACING_REPORTING_HOST', '127.0.0.1'),
            'reporting_port': env.str('TRACING_REPORTING_PORT', '5775')
        },
        'logging': env.bool('TRACING_LOGGING', True)
    }
    DEFAULT_TRACING_CONFIG = {
        'sampler': {
            'type': env.str('TRACING_SAMPLER_TYPE', 'const'),
            'param': env.str('TRACING_SAMPLER_PARAM', "0"),
        }
    }


class DefaultConfig:
    SQLALCHEMY_DATABASE_URI = env.str('SQLALCHEMY_DATABASE_URI')
    SQL_ECHO = env.bool('SQL_ECHO', False)
P
peng.xu 已提交
64
    TRACING_PLUGIN_PATH = env.str('TRACING_PLUGIN_PATH', '')
P
peng.xu 已提交
65
    TRACING_TYPE = env.str('TRACING_TYPE', '')
P
peng.xu 已提交
66
    ROUTER_PLUGIN_PATH = env.str('ROUTER_PLUGIN_PATH', '')
P
peng.xu 已提交
67
    ROUTER_CLASS_NAME = env.str('ROUTER_CLASS_NAME', 'FileBasedHashRingRouter')
P
peng.xu 已提交
68 69
    DISCOVERY_PLUGIN_PATH = env.str('DISCOVERY_PLUGIN_PATH', '')
    DISCOVERY_CLASS_NAME = env.str('DISCOVERY_CLASS_NAME', 'static')
P
peng.xu 已提交
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85


class TestingConfig(DefaultConfig):
    SQLALCHEMY_DATABASE_URI = env.str('SQLALCHEMY_DATABASE_TEST_URI', '')
    SQL_ECHO = env.bool('SQL_TEST_ECHO', False)
    TRACING_TYPE = env.str('TRACING_TEST_TYPE', '')
    ROUTER_CLASS_NAME = env.str('ROUTER_CLASS_TEST_NAME', 'FileBasedHashRingRouter')


if __name__ == '__main__':
    import logging
    logger = logging.getLogger(__name__)
    logger.debug('DEBUG')
    logger.info('INFO')
    logger.warn('WARN')
    logger.error('ERROR')