diff --git a/apps/push_notifications/tasks.py b/apps/push_notifications/tasks.py new file mode 100644 index 0000000..ab0750f --- /dev/null +++ b/apps/push_notifications/tasks.py @@ -0,0 +1,5 @@ +from main import celery_app + +@celery_app.task +def send_push_notification(uuid): + print(uuid) \ No newline at end of file diff --git a/celery.sh b/celery.sh new file mode 100755 index 0000000..6d5b414 --- /dev/null +++ b/celery.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +while ! nc -z $DB_HOST 5432 ; do + echo "APP Waiting for the DB Server" + sleep 3 +done +#python3 manage.py collectstatic --noinput +#python3 manage.py migrate +celery -A main worker --loglevel=info \ No newline at end of file diff --git a/main/__init__.py b/main/__init__.py index e69de29..9e0d95f 100644 --- a/main/__init__.py +++ b/main/__init__.py @@ -0,0 +1,3 @@ +from .celery import app as celery_app + +__all__ = ('celery_app',) \ No newline at end of file diff --git a/main/celery.py b/main/celery.py new file mode 100644 index 0000000..7929e8f --- /dev/null +++ b/main/celery.py @@ -0,0 +1,23 @@ +""" +https://docs.celeryq.dev/en/stable/django/first-steps-with-django.html +""" +import os + +from celery import Celery + +from django.conf import settings + +# this code copied from manage.py +# set the default Django settings module for the 'celery' app. +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'main.settings') + +# you can change the name here +app = Celery("main") + +# read config from Django settings, the CELERY namespace would make celery +# config keys has `CELERY` prefix +app.config_from_object('django.conf:settings', namespace='CELERY') + +# discover and load tasks.py from all registered Django apps +app.autodiscover_tasks(lambda: settings.INSTALLED_APPS) + diff --git a/main/settings.py b/main/settings.py index d3beecc..14c3113 100644 --- a/main/settings.py +++ b/main/settings.py @@ -230,17 +230,30 @@ JALALI_DATE_DEFAULTS = { 'datetime': '%H:%M:%S _ %Y/%m/%d', } } +REDIS_BASE_URL = config('REDIS_BASE_URL') +GOTIFY_ADMIN_CLIENT_TOKEN = config('GOTIFY_ADMIN_CLIENT_TOKEN') CACHES = { "default": { "BACKEND": "django_redis.cache.RedisCache", - "LOCATION": config('BASE_REDIS_URL'), + "LOCATION": config('REDIS_BASE_URL'), "OPTIONS": { "CLIENT_CLASS": "django_redis.client.DefaultClient", } } } +CELERY={ + "broker_url" :REDIS_BASE_URL, + "result_backend" : REDIS_BASE_URL, +} + +CELERY_TASK_TRACK_STARTED = True +CELERY_TASK_TIME_LIMIT = 30 * 60 +CELERY_BROKER_URL = REDIS_BASE_URL +CELERY_RESULT_BACKEND = REDIS_BASE_URL + + # LOGGING = { # 'version': 1, # 'disable_existing_loggers': False, diff --git a/utils/clients/gotify.py b/utils/clients/gotify.py index 0eb9e08..e33f583 100644 --- a/utils/clients/gotify.py +++ b/utils/clients/gotify.py @@ -1,10 +1,11 @@ import time + +from django.conf import settings from django.utils import timezone from typing import Any import httpx import requests -# from django.conf import settings # from django.core.cache import cache from django.db import models from httpx import Request @@ -17,7 +18,8 @@ from gotify_rest_api_client.api.client import create_client from gotify_rest_api_client.api.application import create_app from gotify_rest_api_client.types import Unset -ADMIN_CLIENT_TOKEN = 'CbWdsJrmRTDzbuD' +ADMIN_CLIENT_TOKEN = settings.GOTIFY_ADMIN_CLIENT_TOKEN + import logging