-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py
120 lines (103 loc) · 3.66 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import os
from datetime import timedelta
from logging.config import dictConfig
from pathlib import Path
import sentry_sdk
from pyproj import Transformer
NAME = 'openaedmap-backend'
VERSION = '2.14.0'
CREATED_BY = f'{NAME} {VERSION}'
WEBSITE = 'https://openaedmap.org'
USER_AGENT = f'{NAME}/{VERSION} (+{WEBSITE})'
ENVIRONMENT = os.getenv('ENVIRONMENT')
LOG_LEVEL = 'DEBUG'
POSTGRES_LOG = os.getenv('POSTGRES_LOG', '0').strip().lower() in ('1', 'true', 'yes')
POSTGRES_URL = 'postgresql+asyncpg://postgres@/postgres?host=/tmp/openaedmap-postgres'
VALKEY_URL = os.getenv('VALKEY_URL', 'unix:///tmp/openaedmap-valkey.sock?protocol=3')
DEFAULT_CACHE_MAX_AGE = timedelta(minutes=1)
DEFAULT_CACHE_STALE = timedelta(minutes=5)
COUNTRY_GEOJSON_URL = 'https://osm-countries-geojson.monicz.dev/osm-countries-0-01.geojson.zst'
COUNTRY_UPDATE_DELAY = timedelta(days=float(os.getenv('COUNTRY_UPDATE_DELAY', '1')))
AED_UPDATE_DELAY = timedelta(seconds=30)
AED_REBUILD_THRESHOLD = timedelta(hours=1)
PLANET_REPLICA_URL = 'https://planet.openstreetmap.org/replication/minute/'
PLANET_DIFF_TIMEOUT = timedelta(minutes=5)
TILE_COUNTRIES_CACHE_MAX_AGE = timedelta(hours=4)
TILE_COUNTRIES_CACHE_STALE = timedelta(days=7)
TILE_AEDS_CACHE_STALE = timedelta(days=3)
TILE_COUNTRIES_MAX_Z = 5
TILE_MIN_Z = 3
TILE_MAX_Z = 16
OVERPASS_API_URL = 'https://overpass-api.de/api/interpreter'
OPENSTREETMAP_API_URL = os.getenv('OPENSTREETMAP_API_URL', 'https://api.openstreetmap.org/api/0.6/')
DEFAULT_CHANGESET_TAGS = {
'comment': 'Updated AED image',
'created_by': CREATED_BY,
'website': WEBSITE,
}
CHANGESET_ID_PLACEHOLDER = '__CHANGESET_ID_PLACEHOLDER__'
OSM_PROJ = 'epsg:4326'
MVT_PROJ = 'epsg:3857'
MVT_EXTENT = 4096
MVT_TRANSFORMER = Transformer.from_crs(OSM_PROJ, MVT_PROJ, always_xy=True)
IMAGE_CONTENT_TYPES = {'image/jpeg', 'image/jpg', 'image/png', 'image/webp'}
IMAGE_LIMIT_PIXELS = 6 * 1000 * 1000 # 6 MP (e.g., 3000x2000)
IMAGE_MAX_FILE_SIZE = 2 * 1024 * 1024 # 2 MB
IMAGE_REMOTE_MAX_FILE_SIZE = 10 * 1024 * 1024 # 10 MB
DATA_DIR = Path('data')
PHOTOS_DIR = Path('data/photos')
# Logging configuration
dictConfig(
{
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'default': {
'()': 'uvicorn.logging.DefaultFormatter',
'fmt': '%(levelprefix)s | %(asctime)s | %(name)s: %(message)s',
'datefmt': '%Y-%m-%d %H:%M:%S',
},
},
'handlers': {
'default': {
'formatter': 'default',
'class': 'logging.StreamHandler',
'stream': 'ext://sys.stderr',
},
},
'loggers': {
'root': {'handlers': ['default'], 'level': LOG_LEVEL},
**{
# reduce logging verbosity of some modules
module: {'handlers': [], 'level': 'INFO'}
for module in (
'hpack',
'httpx',
'httpcore',
'multipart',
'python_multipart',
'PIL',
)
},
**{
# conditional database logging
module: {'handlers': [], 'level': 'INFO'}
for module in (
'sqlalchemy.engine',
'sqlalchemy.pool',
)
if POSTGRES_LOG
},
},
}
)
if SENTRY_DSN := os.getenv('SENTRY_DSN'):
sentry_sdk.init(
dsn=SENTRY_DSN,
release=VERSION,
environment=ENVIRONMENT,
enable_tracing=True,
traces_sample_rate=0.2,
trace_propagation_targets=None,
profiles_sample_rate=0.2,
)