chore(): settings improvements
This commit is contained in:
@@ -34,17 +34,25 @@ ALLOWED_HOSTS = env.list(
|
||||
|
||||
# Caching
|
||||
|
||||
REDIS_URI = env("REDIS_URI", default="redis://localhost:6379")
|
||||
REDIS_URI = env("REDIS_URI", default="unique-snowflake")
|
||||
|
||||
CACHES = {
|
||||
"default": {
|
||||
"BACKEND": "django_prometheus.cache.backends.redis.RedisCache",
|
||||
"LOCATION": REDIS_URI,
|
||||
"TIMEOUT": None,
|
||||
"KEY_PREFIX": "backend",
|
||||
"VERSION": 1,
|
||||
},
|
||||
}
|
||||
if REDIS_URI == "unique-snowflake":
|
||||
CACHES = {
|
||||
"default": {
|
||||
"BACKEND": "django.core.cache.backends.locmem.LocMemCache",
|
||||
"LOCATION": "unique-snowflake",
|
||||
}
|
||||
}
|
||||
else:
|
||||
CACHES = {
|
||||
"default": {
|
||||
"BACKEND": "django_prometheus.cache.backends.redis.RedisCache",
|
||||
"LOCATION": REDIS_URI,
|
||||
"TIMEOUT": None,
|
||||
"KEY_PREFIX": "backend",
|
||||
"VERSION": 1,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
# Celery
|
||||
@@ -60,6 +68,20 @@ CELERY_WORKER_SEND_TASK_EVENTS = True
|
||||
CELERY_TASK_SEND_SENT_EVENT = True
|
||||
|
||||
CELERY_TASK_TRACK_STARTED = True
|
||||
CELERY_BEAT_SCHEDULE = {
|
||||
"guardrails-check-all": {
|
||||
"task": "guardrails.check_all",
|
||||
"schedule": 60.0,
|
||||
},
|
||||
"events-cleanup-expired-pending": {
|
||||
"task": "events.cleanup_expired_pending",
|
||||
"schedule": 3600.0,
|
||||
},
|
||||
"notifications-flush-pending": {
|
||||
"task": "notifications.flush_pending",
|
||||
"schedule": 30.0,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
# Database
|
||||
@@ -369,6 +391,16 @@ LOGGING_LOGGERS = {
|
||||
"level": "DEBUG",
|
||||
"propagate": False,
|
||||
},
|
||||
"gunicorn.error": {
|
||||
"handlers": ["console_debug", "console_prod"],
|
||||
"level": "INFO",
|
||||
"propagate": False,
|
||||
},
|
||||
"gunicorn.access": {
|
||||
"handlers": ["console_debug", "console_prod"],
|
||||
"level": "INFO",
|
||||
"propagate": False,
|
||||
},
|
||||
"health-check": {
|
||||
"handlers": ["console_debug", "console_prod"],
|
||||
"level": "INFO" if DEBUG else "ERROR",
|
||||
@@ -386,6 +418,24 @@ LOGGING_LOGGERS = {
|
||||
},
|
||||
}
|
||||
|
||||
OTEL_LOGGING_ENABLED = env.bool(
|
||||
"OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED", default=False
|
||||
)
|
||||
|
||||
if OTEL_LOGGING_ENABLED:
|
||||
LOGGING_HANDLERS["otel"] = {
|
||||
"class": "opentelemetry.sdk._logs.LoggingHandler",
|
||||
"level": "NOTSET",
|
||||
}
|
||||
for _logger_config in LOGGING_LOGGERS.values():
|
||||
if _logger_config.get("handlers") and not _logger_config.get(
|
||||
"propagate", True
|
||||
):
|
||||
_logger_config["handlers"] = [
|
||||
*_logger_config["handlers"],
|
||||
"otel",
|
||||
]
|
||||
|
||||
LOGGING = {
|
||||
"version": 1,
|
||||
"disable_existing_loggers": False,
|
||||
@@ -432,10 +482,29 @@ INSTALLED_APPS = [
|
||||
"apps.flags",
|
||||
"apps.users",
|
||||
"apps.reviews",
|
||||
"apps.experiments",
|
||||
"apps.events",
|
||||
"apps.decision",
|
||||
"apps.metrics",
|
||||
"apps.guardrails",
|
||||
"apps.reports",
|
||||
"apps.notifications",
|
||||
"apps.learnings",
|
||||
"apps.conflicts",
|
||||
# API v1 apps
|
||||
"api.v1.auth",
|
||||
"api.v1.flags",
|
||||
"api.v1.users",
|
||||
"api.v1.reviews",
|
||||
"api.v1.experiments",
|
||||
"api.v1.decision",
|
||||
"api.v1.events",
|
||||
"api.v1.guardrails",
|
||||
"api.v1.reports",
|
||||
"api.v1.metrics",
|
||||
"api.v1.notifications",
|
||||
"api.v1.learnings",
|
||||
"api.v1.conflicts",
|
||||
]
|
||||
|
||||
# GUID
|
||||
@@ -576,6 +645,15 @@ TEST_NON_SERIALIZED_APPS: list[str] = []
|
||||
|
||||
TEST_RUNNER = "django.test.runner.DiscoverRunner"
|
||||
|
||||
import sys # noqa: E402
|
||||
|
||||
if "test" in sys.argv:
|
||||
CACHES = {
|
||||
"default": {
|
||||
"BACKEND": "django.core.cache.backends.locmem.LocMemCache",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
# URLs
|
||||
|
||||
|
||||
Reference in New Issue
Block a user