-
Notifications
You must be signed in to change notification settings - Fork 32
/
config.py
74 lines (57 loc) · 1.99 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
64
65
66
67
68
69
70
71
72
73
74
"""Sanic app configuration.
Some configuration is hard-coded here, but most is provided via
environment variables.
"""
from dataclasses import dataclass
from logging import getLogger
from logging.config import dictConfig
from os import environ
from typing import Tuple
import json
log_level = environ.get("LOG_LEVEL", "DEBUG").upper()
dictConfig(
{
"version": 1,
"formatters": {
"json": {
"()": "dockerflow.logging.JsonLogFormatter",
"logger_name": "ingestion-edge",
}
},
"handlers": {
"console": {
"level": log_level,
"class": "logging.StreamHandler",
"formatter": "json",
}
},
"loggers": {
"request.summary": {"handlers": ["console"], "level": log_level},
"ingestion-edge": {"handlers": ["console"], "level": log_level},
},
}
)
logger = getLogger("ingestion-edge")
@dataclass
class Route:
"""Dataclass for entries in ROUTE_TABLE."""
uri: str
topic: str
methods: Tuple = ("POST", "PUT")
ROUTE_TABLE = [Route(*route) for route in json.loads(environ.get("ROUTE_TABLE", "[]"))]
QUEUE_PATH = environ.get("QUEUE_PATH", "queue")
MINIMUM_DISK_FREE_BYTES = int(environ.get("MINIMUM_DISK_FREE_BYTES", 0)) or None
with open("metadata_headers.json", "r") as fp:
METADATA_HEADERS = {
header: header.replace("-", "_")
for raw in json.load(fp)
for header in (raw.strip().lower(),)
if header
}
PUBLISH_TIMEOUT_SECONDS = float(environ.get("PUBLISH_TIMEOUT_SECONDS", 1))
FLUSH_CONCURRENT_BYTES = int(environ.get("FLUSH_CONCURRENT_BYTES", 1e7))
FLUSH_CONCURRENT_MESSAGES = int(environ.get("FLUSH_CONCURRENT_MESSAGES", 1000))
FLUSH_SLEEP_SECONDS = float(environ.get("FLUSH_SLEEP_SECONDS", 1))
def get_config_dict() -> dict:
"""Return the config values from this module as a dict."""
return {key: value for key, value in globals().items() if key == key.upper()}