diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..0550d5b --- /dev/null +++ b/.env.example @@ -0,0 +1,15 @@ +# ======================================== +# Variables de Entorno (Plantilla) +# ======================================== +DEBUG=True +SECRET_KEY=django-insecure-r9n6j1_h%@uqoz0bjz^mq=t72o0t*j@84jpl%_i4^qu%&+**u7 +ALLOWED_HOSTS=* + +# === CONFIGURACIÓN LOCAL (Para usar start.sh sin Docker) === +# Deja estas variables vacías o comentadas para usar SQLite y Memory Channel. +# DATABASE_URL= +# REDIS_URL= + +# === CONFIGURACIÓN DOCKER (Descomentar para Producción/Docker) === +# DATABASE_URL=postgres://efintel_user:efintel_password@db:5432/efintel_db +# REDIS_URL=redis://redis:6379/0 diff --git a/config/settings.py b/config/settings.py index 2ea9eaa..0ba6333 100644 --- a/config/settings.py +++ b/config/settings.py @@ -160,8 +160,8 @@ MAILERS = { } # Celery Configuration -CELERY_BROKER_URL = env('REDIS_URL', default='redis://localhost:6379/0') -CELERY_RESULT_BACKEND = env('REDIS_URL', default='redis://localhost:6379/0') +CELERY_BROKER_URL = env('REDIS_URL', default='memory://') +CELERY_RESULT_BACKEND = env('REDIS_URL', default='cache+memory://') CELERY_ACCEPT_CONTENT = ['json'] CELERY_TASK_SERIALIZER = 'json' CELERY_RESULT_SERIALIZER = 'json' diff --git a/patch_settings.py b/patch_settings.py new file mode 100644 index 0000000..070616c --- /dev/null +++ b/patch_settings.py @@ -0,0 +1,42 @@ +import re + +with open('config/settings.py', 'r') as f: + content = f.read() + +# Replace CHANNEL_LAYERS +old_channels = """CHANNEL_LAYERS = { + "default": { + "BACKEND": "channels_redis.core.RedisChannelLayer", + "CONFIG": { + "hosts": [env('REDIS_URL', default='redis://localhost:6379/0')], + }, + }, +}""" +new_channels = """REDIS_URL = env('REDIS_URL', default=None) +if REDIS_URL: + CHANNEL_LAYERS = { + "default": { + "BACKEND": "channels_redis.core.RedisChannelLayer", + "CONFIG": { + "hosts": [REDIS_URL], + }, + }, + } +else: + CHANNEL_LAYERS = { + "default": { + "BACKEND": "channels.layers.InMemoryChannelLayer" + } + }""" +content = content.replace(old_channels, new_channels) + +# Replace Celery defaults so they don't crash if REDIS_URL is None +old_celery1 = "CELERY_BROKER_URL = env('REDIS_URL', default='redis://localhost:6379/0')" +new_celery1 = "CELERY_BROKER_URL = env('REDIS_URL', default='memory://')" +old_celery2 = "CELERY_RESULT_BACKEND = env('REDIS_URL', default='redis://localhost:6379/0')" +new_celery2 = "CELERY_RESULT_BACKEND = env('REDIS_URL', default='cache+memory://')" +content = content.replace(old_celery1, new_celery1) +content = content.replace(old_celery2, new_celery2) + +with open('config/settings.py', 'w') as f: + f.write(content)