add celery

This commit is contained in:
Sayyid Hamid Mahdavi 2025-07-15 17:32:06 +03:30
parent e442f00cb0
commit ff3e5d3bed
6 changed files with 57 additions and 3 deletions

View file

@ -0,0 +1,5 @@
from main import celery_app
@celery_app.task
def send_push_notification(uuid):
print(uuid)

8
celery.sh Executable file
View file

@ -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

View file

@ -0,0 +1,3 @@
from .celery import app as celery_app
__all__ = ('celery_app',)

23
main/celery.py Normal file
View file

@ -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)

View file

@ -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,

View file

@ -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