add celery
This commit is contained in:
parent
7a47f3e3d0
commit
68f0dd13db
5 changed files with 62 additions and 1 deletions
8
celery.sh
Executable file
8
celery.sh
Executable 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
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
from .celery import app as celery_app
|
||||
|
||||
__all__ = ('celery_app',)
|
||||
23
main/celery.py
Normal file
23
main/celery.py
Normal 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)
|
||||
|
||||
|
|
@ -78,6 +78,13 @@ REST_FRAMEWORK = {
|
|||
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination',
|
||||
'PAGE_SIZE': 200,
|
||||
"DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema",
|
||||
# 'DEFAULT_THROTTLE_CLASSES': [
|
||||
# 'rest_framework.throttling.AnonRateThrottle',
|
||||
# ],
|
||||
'DEFAULT_THROTTLE_RATES': {
|
||||
# 'otp_min': '1/min',
|
||||
# 'otp_day': '20/day',
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -152,7 +159,7 @@ JALALI_DATE_DEFAULTS = {
|
|||
CACHES = {
|
||||
"default": {
|
||||
"BACKEND": "django_redis.cache.RedisCache",
|
||||
"LOCATION": config('BASE_REDIS_URL'),
|
||||
"LOCATION": config('REDIS_BASE_URL'),
|
||||
"OPTIONS": {
|
||||
"CLIENT_CLASS": "django_redis.client.DefaultClient",
|
||||
}
|
||||
|
|
@ -264,3 +271,18 @@ MINIO_HTTP_CLIENT: urllib3.poolmanager.PoolManager = urllib3.PoolManager(
|
|||
status_forcelist=[500, 502, 503, 504]
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
REDIS_BASE_URL = config('REDIS_BASE_URL')
|
||||
|
||||
|
||||
|
||||
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
|
||||
5
utils/tasks.py
Normal file
5
utils/tasks.py
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
from main import celery_app
|
||||
|
||||
@celery_app.task
|
||||
def sample_task(param):
|
||||
print(param)
|
||||
Loading…
Add table
Reference in a new issue