Ujwal Bhargav
Ujwal Bhargav

Reputation: 56

Django Celery Results Table Missing periodictaskname and taskname Fields

I have set up Django with Celery, using django_celery_results and django_celery_beat to schedule tasks and store the results. The tasks are running successfully, but I've encountered an issue with the django_celery_results table.

The django_celery_results table in my database only contains UUID, task state, and completed time. However, I expected to see additional fields such as periodictaskname and taskname. The absence of these fields is causing difficulties in tracking and managing scheduled tasks.

`#celery.py`
celery.conf.result_backend = os.environ.get('DATABASE_URL')

I have reviewed the documentation for django_celery_results and django_celery_beat but couldn't find a clear solution. I also checked my Celery configuration, and everything seems to be in order.

I expect the django_celery_results table to include fields such as periodictaskname and taskname in addition to UUID, task state, and completed time.

Upvotes: 1

Views: 1023

Answers (3)

gred_dev
gred_dev

Reputation: 1

put CELERY_RESULT_EXTENDED = True in my settings.py and restart the workerd for me!

Upvotes: 0

Ujwal Bhargav
Ujwal Bhargav

Reputation: 56

In settings.py we need to have CELERY_RESULT_EXTENDED =True for the taskname to show up in the celery results table. This does show the task name and worker name but the periodic taskname is not getting populated.

Upvotes: 1

M Burak
M Burak

Reputation: 109

django_celery_results alredy includes these fields: Task ID, Periodic Task Name, Task Name, Completed DateTime, Task State, Worker.

Please be sure django_celery_results is added to INSTALLED_APPS in settings.py:

INSTALLED_APPS = [
    ...
    "celery",
    "django_celery_beat",
    "django_celery_results",
    ...
]

Please do not forget database migration after adding apps. Then, you should return result in dict type, after celery tasks done like this sample:

@shared_task(bind=True)
def analyze_all_posts(self, *args, **kwarg):
    posts = Post.objects.all()  # Example
    try:
        return {"status": True, "message": f"{len(posts)} post(s) analyzed"}
    except Exception as e:
        return {"status": False, "message": str(e)}

Upvotes: 0

Related Questions