celery + django - how to write task state to database

℡╲_俬逩灬. 提交于 2019-12-05 06:04:03

问题


I'm running Celery with Django and RabbitMQ and want to see the task states in the database table. Unfortunately no entries are written into the table djcelery_taskstate and I can't figure out why.

My settings:

CELERY_ENABLE_UTC = True
BROKER_URL = "amqp://guest:guest@localhost:5672/"
CELERY_RESULT_BACKEND = "database"
CELERYBEAT_SCHEDULER = 'djcelery.schedulers.DatabaseScheduler'

CELERY_TRACK_STARTED = True
CELERY_SEND_EVENTS = True

CELERY_IMPORTS = ("project_management.tasks", "accounting.tasks", "time_tracking.tasks", )
CELERY_ALWAYS_EAGER = False

import djcelery
djcelery.setup_loader()

My Task:

class TestTask(Task):

    def run(self, po_id):
        self.update_state(state=states.STARTED, meta={'total': 0, 'done': False})
        #do something..
        self.update_state(state=states.SUCCESS, meta={'total': 100, 'done': True})

I'm starting the task as follows in a view:

TestTask.apply_async(args=[], kwargs={})

I'm starting celery workers as follows.

python manage.py celeryd -v 1 -B -s celery -E -l INFO

Console gives me the following output:

[2013-05-19 11:10:03,774: INFO/MainProcess] Task accounting.tasks.TestTask[5463b2ed-0eba-451d-b828-7a89fcd36348] succeeded in 0.0538640022278s: None

Any idea what is wrong with my setup?


回答1:


You need to start up the snapshot camera as well in order to see the results in the database.

python manage.py celerycam

Once you have that running, you will be able to see entries in the djcelery tables.



来源:https://stackoverflow.com/questions/16633107/celery-django-how-to-write-task-state-to-database

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!