Search code examples
djangocelerydjango-celery

Saving result of celery group task in django database using TaskSetMeta model


I'm creating group of tasks and adding them to a queue.

def process(self, request, queryset):
    tasks = group([
        mytask.s(user_id=obj.id)
        for obj in list(queryset)
    ])
    result = tasks.applay_async()

Results of each separate task are saved in django database in model TaskMeta according to settings:

CELERY_TASK_SERIALIZER='json'
CELERY_RESULT_SERIALIZER='json'
CELERY_RESULT_BACKEND='djcelery.backends.database:DatabaseBackend'

However, I can't see any new rows for model TaskSetMeta.

Is this model designed to work only with celery.task.sets.TaskSet object, which is currently deprecated?


Solution

  • In django-celery does not automaticlly save result of group() and TaskSetMeta as it is in case of single task and TaskMeta. To create record in TaskSetMeta for creating group tasks you have to call .save() at the end:

    def process(self, request, queryset):
        tasks = group([
            mytask.s(user_id=obj.id)
            for obj in list(queryset)
        ])
        result = tasks.apply_async()
        result.save()