I am using django celery(4.2) and I will add some task from my django view, also I want to get the task result async in a separate process, but when I try to get the result, I got some errors.
My full steps is as following:
- django celery config:
proj/settings/celery.py
import os
from celery import Celery
from django.conf import settings
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'Nuwa.settings.development')
app = Celery('Nuwa')
app.config_from_object('django.conf:settings', namespace='CELERY')
app.autodiscover_tasks()
proj/settings.py
CELERY_BROKER_URL = f'redis://{REDIS["HOST"]}:{REDIS["PORT"]}'
CELERY_RESULT_BACKEND = f'redis://{REDIS["HOST"]}:{REDIS["PORT"]}'
CELERY_ACCEPT_CONTENT = ['application/json']
CELERY_RESULT_SERIALIZER = 'json'
CELERY_TASK_SERIALIZER = 'json'
proj/settings/init.py
from .celery import app as celery_app
__all__ = ('celery_app', )
- call celery task in one django view:
result = port_scan.delay(target)
redis_conn.sadd(celery_task_set_key, result.task_id)
in this step, I store the task_id in redis set for future use.
- get the task result
redis_conn = redis.Redis(host=REDIS_HOST, port=REDIS_PORT)
celery_tasks = redis_conn.smembers('celery-tasks')
for task_id in celery_tasks:
print(task_id)
celery_result = AsyncResult(task_id)
print(celery_result.state)
when I try to get the result, it have error:
AttributeError: 'DisabledBackend' object has no attribute '_get_task_meta_for'
I try some solutions by search google and so, it doesn't work.