Skip to content

Commit

Permalink
feat: remove django-celery-results
Browse files Browse the repository at this point in the history
Signed-off-by: Guilhem Barthés <guilhem.barthes@owkin.com>
  • Loading branch information
guilhem-barthes committed Sep 4, 2024
1 parent 0f111a9 commit 3cd0918
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 11 deletions.
1 change: 0 additions & 1 deletion backend/backend/settings/api/events/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
INSTALLED_APPS = [
"django.contrib.auth",
"django.contrib.contenttypes",
"django_celery_results",
"rest_framework",
"api",
"substrapp",
Expand Down
1 change: 0 additions & 1 deletion backend/backend/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
"django.contrib.messages",
"django.contrib.staticfiles",
"django.contrib.sites",
"django_celery_results",
"rest_framework",
"rest_framework_simplejwt.token_blacklist",
"substrapp",
Expand Down
17 changes: 13 additions & 4 deletions backend/backend/settings/deps/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,47 @@
"""

import os
import typing

from substrapp.compute_tasks.errors import CeleryRetryError

from .org import ORG_NAME


def build_broker_url(user: str, password: str, host: str, port: str) -> str:
def build_redis_url(user: str, password: str, host: str, port: str, db: typing.Optional[int] = None) -> str:
"""Builds a redis connection string
Args:
user (str): redis user
password (str): redis password
host (str): redis hostname
port (str): redis port
db (typing.Optional[str]): redis database. Accepted values are None (default value) or 0 to 15.
Returns:
str: a connection string of the form "redis://user:password@hostname:port//"
str: a connection string of the form "redis://user:password@hostname:port/db"
"""
conn_info = ""
conn_port = ""
conn_db = ""
if user and password:
conn_info = f"{user}:{password}@"
if port:
conn_port = f":{port}"
return f"redis://{conn_info}{host}{conn_port}//"
if db is not None:
conn_db = str(db)
return f"redis://{conn_info}{host}{conn_port}/{conn_db}/"


CELERY_BROKER_USER = os.environ.get("CELERY_BROKER_USER")
CELERY_BROKER_PASSWORD = os.environ.get("CELERY_BROKER_PASSWORD")
CELERY_BROKER_HOST = os.environ.get("CELERY_BROKER_HOST", "localhost")
CELERY_BROKER_PORT = os.environ.get("CELERY_BROKER_PORT", "5672")
CELERY_BROKER_URL = build_broker_url(CELERY_BROKER_USER, CELERY_BROKER_PASSWORD, CELERY_BROKER_HOST, CELERY_BROKER_PORT)
CELERY_BROKER_URL = build_redis_url(CELERY_BROKER_USER, CELERY_BROKER_PASSWORD, CELERY_BROKER_HOST, CELERY_BROKER_PORT)

CELERY_RESULT_BACKEND = build_redis_url(
CELERY_BROKER_USER, CELERY_BROKER_PASSWORD, CELERY_BROKER_HOST, CELERY_BROKER_PORT, db=1
)

CELERY_ACCEPT_CONTENT = ["application/json"]
CELERY_RESULT_SERIALIZER = "json"
Expand Down
1 change: 0 additions & 1 deletion backend/backend/settings/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,4 @@
SITE_PORT = DEFAULT_PORT
DEFAULT_DOMAIN = os.environ.get("DEFAULT_DOMAIN", f"http://{SITE_HOST}:{SITE_PORT}")

CELERY_RESULT_BACKEND = "django-db"
CELERY_TASK_MAX_RETRIES = int(os.environ.get("CELERY_TASK_MAX_RETRIES", 0))
2 changes: 0 additions & 2 deletions backend/backend/settings/prod.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@
SITE_PORT = os.environ.get("SITE_PORT", DEFAULT_PORT)
DEFAULT_DOMAIN = os.environ.get("DEFAULT_DOMAIN", f"http://{SITE_HOST}:{SITE_PORT}")

CELERY_RESULT_BACKEND = "django-db"

# Password validation
# https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators

Expand Down
1 change: 0 additions & 1 deletion backend/backend/settings/worker/events/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
INSTALLED_APPS = [
"django.contrib.auth",
"django.contrib.contenttypes",
"django_celery_results",
"rest_framework",
"substrapp",
"api",
Expand Down
1 change: 0 additions & 1 deletion backend/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ celery==5.3.6
checksumdir==1.2.0
cryptography==42.0.5
django-cors-headers==4.4.0
django-celery-results==2.5.1
djangorestframework==3.15.2
djangorestframework-simplejwt==5.2.2
drf-spectacular==0.25.1
Expand Down

0 comments on commit 3cd0918

Please sign in to comment.