TypeError: 'TaskRegistry' object is not callable
celery.py
# celery.py
from __future__ import absolute_import, unicode_literals
from celery import Celery
from celery.app import app_or_default
class Scheduler(object):
def __init__(self, app=None):
self.app = app_or_default(app)
app = Celery("celery_tasks", broker='redis://127.0.0.1/0', backend='redis://127.0.0.1/1', include=[
'celery_tasks.tasks',
])
app.conf.update(
result_expires=3600,
task_routes = {
'celery.tasks.add': {'queue': 'hipri'},
}
)
app.conf.timezone = 'Europe/London'
if __name__ == '__main__':
app.start()
运行代码时,会出现下面的问题:
在celery.py文件中安装下图操作:
进入base.py文件:
处理调用时,会出现如上tasks不可调用问题,在源码中检查发现,Celery
中带有的是task
方法,没有tasks
方法。
需要修改为@celery_app.task
即可