-
Notifications
You must be signed in to change notification settings - Fork 180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ON HOLD] Django settings cleanup, logging improvements and critical fixes #585
base: main
Are you sure you want to change the base?
Changes from 2 commits
f916363
47d08fe
d285c4d
267e122
c8b200b
3283054
036637b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
DJANGO_SETTINGS_MODULE='backend.settings.celery' | ||
|
||
# Default log level | ||
DEFAULT_LOG_LEVEL="INFO" | ||
|
||
# Postgres DB envs | ||
DB_HOST='unstract-db' | ||
DB_USER='unstract_dev' | ||
DB_PASSWORD='unstract_pass' | ||
DB_NAME='unstract_db' | ||
DB_PORT=5432 | ||
|
||
# Redis | ||
REDIS_HOST="unstract-redis" | ||
REDIS_PORT=6379 | ||
REDIS_PASSWORD="" | ||
REDIS_USER=default | ||
|
||
# Protocol buffers generated code. | ||
PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python | ||
|
||
# Enable logging of workflow history. | ||
ENABLE_LOG_HISTORY=True | ||
# Interval in seconds for periodic consumer operations. | ||
LOG_HISTORY_CONSUMER_INTERVAL=30 | ||
# Maximum number of logs to insert in a single batch. | ||
LOGS_BATCH_LIMIT=30 | ||
|
||
# Celery Configuration | ||
CELERY_BROKER_URL="redis://unstract-redis:6379" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +0,0 @@ | ||
from .celery_service import app as celery_app | ||
|
||
__all__ = ["celery_app"] | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,13 +8,17 @@ | |
|
||
import os | ||
|
||
from django.core.asgi import get_asgi_application | ||
from dotenv import load_dotenv | ||
from dotenv import find_dotenv, load_dotenv | ||
|
||
load_dotenv(find_dotenv() or "") | ||
|
||
load_dotenv() | ||
|
||
os.environ.setdefault( | ||
"DJANGO_SETTINGS_MODULE", | ||
os.environ.get("DJANGO_SETTINGS_MODULE", "backend.settings.dev"), | ||
os.environ.get("DJANGO_SETTINGS_MODULE", "backend.settings.platform"), | ||
) | ||
|
||
from django.core.asgi import get_asgi_application # noqa: E402 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why this move to down? Is it for getting envs/settings before loading asgi? |
||
|
||
application = get_asgi_application() |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import os | ||
from typing import Any, Optional | ||
from urllib.parse import quote_plus | ||
|
||
from backend.constants import FeatureFlag | ||
|
||
# Requires PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python env setting | ||
# to be loaded prior. | ||
from unstract.flags.feature_flag import check_feature_flag_status | ||
|
||
missing_settings = [] | ||
|
||
|
||
def get_required_setting( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @hari-kuriakose we need to check missing_settings and raise error. Else using the |
||
setting_key: str, default: Optional[Any] = None | ||
) -> Optional[str]: | ||
"""Get the value of an environment variable specified by the given key. Add | ||
missing keys to `missing_settings` so that exception can be raised at the | ||
end. | ||
|
||
Args: | ||
key (str): The key of the environment variable | ||
default (Optional[str], optional): Default value to return incase of | ||
env not found. Defaults to None. | ||
|
||
Returns: | ||
Optional[str]: The value of the environment variable if found, | ||
otherwise the default value. | ||
""" | ||
data = os.environ.get(setting_key, default) | ||
if not data: | ||
missing_settings.append(setting_key) | ||
return data | ||
|
||
|
||
DB_NAME = os.environ.get("DB_NAME", "unstract_db") | ||
DB_USER = os.environ.get("DB_USER", "unstract_dev") | ||
DB_HOST = os.environ.get("DB_HOST", "backend-db-1") | ||
DB_PASSWORD = os.environ.get("DB_PASSWORD", "unstract_pass") | ||
DB_PORT = os.environ.get("DB_PORT", 5432) | ||
if check_feature_flag_status(FeatureFlag.MULTI_TENANCY_V2): | ||
DB_ENGINE = "django.db.backends.postgresql" | ||
else: | ||
DB_ENGINE = "django_tenants.postgresql_backend" | ||
|
||
|
||
REDIS_USER = os.environ.get("REDIS_USER", "default") | ||
REDIS_PASSWORD = os.environ.get("REDIS_PASSWORD", "") | ||
REDIS_HOST = os.environ.get("REDIS_HOST", "unstract-redis") | ||
REDIS_PORT = os.environ.get("REDIS_PORT", "6379") | ||
REDIS_DB = os.environ.get("REDIS_DB", "") | ||
|
||
ENABLE_LOG_HISTORY = get_required_setting("ENABLE_LOG_HISTORY") | ||
LOG_HISTORY_CONSUMER_INTERVAL = int( | ||
get_required_setting("LOG_HISTORY_CONSUMER_INTERVAL", "60") | ||
) | ||
LOGS_BATCH_LIMIT = int(get_required_setting("LOGS_BATCH_LIMIT", "30")) | ||
|
||
CORS_ALLOWED_ORIGINS = [ | ||
"http://localhost:3000", | ||
"http://127.0.0.1:3000", | ||
"http://frontend.unstract.localhost", | ||
# Other allowed origins if needed | ||
] | ||
|
||
# Database | ||
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases | ||
DATABASES = { | ||
"default": { | ||
"ENGINE": DB_ENGINE, | ||
"NAME": f"{DB_NAME}", | ||
"USER": f"{DB_USER}", | ||
"HOST": f"{DB_HOST}", | ||
"PASSWORD": f"{DB_PASSWORD}", | ||
"PORT": f"{DB_PORT}", | ||
"ATOMIC_REQUESTS": True, | ||
} | ||
} | ||
|
||
# SocketIO connection manager | ||
SOCKET_IO_MANAGER_URL = f"redis://{REDIS_HOST}:{REDIS_PORT}" | ||
|
||
CELERY_BROKER_URL = get_required_setting( | ||
"CELERY_BROKER_URL", f"redis://{REDIS_HOST}:{REDIS_PORT}" | ||
) | ||
# CELERY_RESULT_BACKEND = f"redis://{REDIS_HOST}:{REDIS_PORT}/1" | ||
# Postgres as result backend | ||
CELERY_RESULT_BACKEND = ( | ||
f"db+postgresql://{DB_USER}:{quote_plus(DB_PASSWORD)}" | ||
f"@{DB_HOST}:{DB_PORT}/{DB_NAME}" | ||
) | ||
CELERY_ACCEPT_CONTENT = ["json"] | ||
CELERY_TASK_SERIALIZER = "json" | ||
CELERY_RESULT_SERIALIZER = "json" | ||
CELERY_TIMEZONE = "UTC" | ||
CELERY_TASK_MAX_RETRIES = 3 | ||
CELERY_TASK_RETRY_BACKOFF = 60 # Time in seconds before retrying the task | ||
|
||
|
||
INSTALLED_APPS = ["django.contrib.contenttypes", "django_celery_beat"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hari-kuriakose isn't this the default params / behaviour of the
load_dotenv()
?load_dotenv()
again?