diff --git a/README.md b/README.md index dd3b6bb..fd6a534 100644 --- a/README.md +++ b/README.md @@ -106,3 +106,20 @@ Use a program like `gtranslator` or `poedit` to start translations | Edit adoption notice | User that created, Moderator, Admin | | Edit animal | User that created, Moderator, Admin | | Add animal/photo to adoption notice | User that created, Moderator, Admin | + +# Celery and KeyDB + +Start KeyDB docker container +```zsh +docker run -d --name keydb -p 6379:6379 eqalpha/keydb +``` + +Start worker +```zsh + celery -A notfellchen.celery worker +``` + +Start beat +```zsh + celery -A notfellchen.celery beat +``` diff --git a/pyproject.toml b/pyproject.toml index 29508eb..9ec4434 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -38,7 +38,8 @@ dependencies = [ "psycopg2-binary", "django-crispy-forms", "crispy-bootstrap4", - "djangorestframework" + "djangorestframework", + "celery[redis]" ] dynamic = ["version", "readme"] diff --git a/src/fellchensammlung/tasks.py b/src/fellchensammlung/tasks.py new file mode 100644 index 0000000..174aad6 --- /dev/null +++ b/src/fellchensammlung/tasks.py @@ -0,0 +1,6 @@ +from notfellchen.celery import app as celery_app +from .tools.admin import clean_locations + +@celery_app.task(name="admin.clean_locations") +def task_clean_locations(): + clean_locations() diff --git a/src/fellchensammlung/tools/admin.py b/src/fellchensammlung/tools/admin.py index 774097d..56188ad 100644 --- a/src/fellchensammlung/tools/admin.py +++ b/src/fellchensammlung/tools/admin.py @@ -7,7 +7,7 @@ def clean_locations(quiet=True): num_without_location = adoption_notices_without_location.count() if not quiet: print(f"From {num_of_all} there are {num_without_location} adoption notices without location " - f"({num_without_location/num_of_all*100:.2f}%)") + f"({num_without_location / num_of_all * 100:.2f}%)") for adoption_notice in adoption_notices_without_location: if not quiet: print(f"Searching {adoption_notice.location_string} in Nominatim") @@ -28,7 +28,7 @@ def clean_locations(quiet=True): num_without_location = rescue_orgs_without_location.count() if not quiet: print(f"From {num_of_all} there are {num_without_location} adoption notices without location " - f"({num_without_location/num_of_all*100:.2f}%)") + f"({num_without_location / num_of_all * 100:.2f}%)") for rescue_org in rescue_orgs_without_location: if not quiet: print(f"Searching {rescue_org.location_string} in Nominatim") @@ -41,4 +41,4 @@ def clean_locations(quiet=True): num_without_location_new = rescue_orgs_without_location_new.count() num_new = num_without_location - num_without_location_new if not quiet: - print(f"Added {num_new} new locations") \ No newline at end of file + print(f"Added {num_new} new locations") diff --git a/src/notfellchen/settings.py b/src/notfellchen/settings.py index 6130b07..0d8eb5a 100644 --- a/src/notfellchen/settings.py +++ b/src/notfellchen/settings.py @@ -14,6 +14,7 @@ from pathlib import Path import os import configparser from django.utils.translation import gettext_lazy as _ +from celery import Celery """CONFIG PARSER """ config = configparser.RawConfigParser() @@ -79,6 +80,11 @@ DB_HOST = config.get("database", "host", fallback='') BASE_DIR = Path(__file__).resolve().parent.parent LOCALE_PATHS = [os.path.join(BASE_DIR, 'locale')] +""" CELERY + KEYDB """ +CELERY_BROKER_URL = config.get("celery", "broker", fallback="redis://localhost:6379/0") +CELERY_RESULT_BACKEND = config.get("celery", "backend", fallback="redis://localhost:6379/0") + + """ GEOCODING """ GEOCODING_API_URL = config.get("geocoding", "api_url", fallback="https://nominatim.hyteck.de/search") """ Tile Server """