Skip to content

Commit

Permalink
encode password so connection strings are always valid
Browse files Browse the repository at this point in the history
  • Loading branch information
daveminer committed Sep 8, 2024
1 parent e490930 commit ca7ebf1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion bert_serv/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.1/ref/settings/
"""
"""s

import environ
import os
Expand Down
7 changes: 5 additions & 2 deletions celeryconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@
db_host = os.environ.get('DB_HOST', 'localhost')
db_port = os.environ.get('DB_PORT', 5432)

encoded_celery_password = urllib.parse.quote_plus(celery_password)
encoded_db_password = urllib.parse.quote_plus(db_password)

# Celery config
broker_url = f'amqp://{celery_user}:{celery_password}@{celery_host}:{celery_port}'
broker_url = f'amqp://{celery_user}:{encoded_celery_password}@{celery_host}:{celery_port}'
include = ['sentiment.tasks']
result_backend = f'db+postgresql://{db_user}:{db_password}@{db_host}:{db_port}'
result_backend = f'db+postgresql://{db_user}:{encoded_db_password}@{db_host}:{db_port}'
result_expires = 3600
8 changes: 8 additions & 0 deletions sentiment/celery.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import os
from celery import Celery
from pathlib import Path

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'bert_serv.settings')
os.environ.setdefault('CELERY_CONFIG_MODULE', 'celeryconfig')

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent

# Load from .env
environ.Env.read_env(os.path.join(BASE_DIR, '.env'))

app = Celery('bert_serv')

app.config_from_envvar('CELERY_CONFIG_MODULE')
app.autodiscover_tasks()


if __name__ == '__main__':
app.start()

0 comments on commit ca7ebf1

Please sign in to comment.