Test if a celery task is still being processed

后端 未结 2 1721
余生分开走
余生分开走 2021-02-08 02:20

How can I test if a task (task_id) is still processed in celery? I have the following scenario:

  1. Start a task in a Django view
  2. Store the BaseAsyncResult in
2条回答
  •  鱼传尺愫
    2021-02-08 02:24

    define a field (PickledObjectField) in your model to store the celery task:

    class YourModel(models.Model):
        .
        .
        celery_task = PickledObjectField()
        .
        .
    
        def task():
            self.celery_task = SubmitTask.apply_async(args = self.task_detail())
            self.save()
    

    In case your task is not specific on any model you should create one specifically for the celery tasks.

    or else I suggest using django-celery. It has a nice monitoring feature:
    http://ask.github.com/celery/userguide/monitoring.html#django-admin-monitor, saves the tasks details in a django model in a nice graphical way.

提交回复
热议问题