Djando Celery: Celery task does not create record in DB

安稳与你 提交于 2019-12-06 15:27:05

Django server(root) and celery(celery_user) tasks were run by different users, therefore, celery_user has not got write access to the database. So then task.apply() is run by root and can save() records and task.apply_async() - by celery_user and cannot.

The short-term solution for this problem was to make celery_user the owner of the database (development env using sqlite3):

chown celery_user:celery_user db.sqlite3

Although, Adding a group to the celery_user would be more appropriate (for short-term).

Or long term - run everything with unprivileged users https://www.syncano.io/blog/configuring-running-django-celery-docker-containers-pt-1/

p.s.: I was having some problems with http://docs.celeryproject.org/en/latest/reference/celery.contrib.rdb.html (debugging tool for celery). Telnet was disconnected every time the task was received (i.e. every 30 seconds). Make sure that You are using task which is dedicated for debugging.

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