Здравствуйте! Только осваиваю веб после перехода с десктопа.
Нужно реализовать фоновое выполнение задач, для которого выбрал Celery. Сам проект на фреймворке Django, но пока хочу попробовать чисто Celery.
Что я сделал:
- установил celery в виртуальное окружение
- установил rabbitmq
- создал отдельную папку, в которой файл tasks.py и celery.py
Содержимое tasks.pyfrom celery import Celery
app = Celery('tasks', backend='amqp', broker='amqp://')
@app.tasks
def print_hello():
print ("Hello")
Содержимое celery.py (то, что нашел в интернете, типо конфиги)from __future__ import absolute_import, unicode_literals
from celery import Celery
app = Celery('proj',
broker='amqp://',
backend='amqp://',
include=['proj.tasks'])
# Optional configuration, see the application user guide.
app.conf.update(
result_expires=3600,
)
if __name__ == '__main__':
app.start()
Запускаю так:
(ENV) root@cs53546:/home/analytics/messages# celery worker -A tasks
Получаю это:Traceback (most recent call last):
File "/home/analytics/ENV/bin/celery", line 11, in <module>
sys.exit(main())
File "/home/analytics/ENV/lib/python3.5/site-packages/celery/__main__.py", line 14, in main
_main()
File "/home/analytics/ENV/lib/python3.5/site-packages/celery/bin/celery.py", line 326, in main
cmd.execute_from_commandline(argv)
File "/home/analytics/ENV/lib/python3.5/site-packages/celery/bin/celery.py", line 488, in execute_from_commandline
super(CeleryCommand, self).execute_from_commandline(argv)))
File "/home/analytics/ENV/lib/python3.5/site-packages/celery/bin/base.py", line 276, in execute_from_commandline
argv = self.setup_app_from_commandline(argv)
File "/home/analytics/ENV/lib/python3.5/site-packages/celery/bin/base.py", line 478, in setup_app_from_commandline
self.app = self.find_app(app)
File "/home/analytics/ENV/lib/python3.5/site-packages/celery/bin/base.py", line 500, in find_app
return find_app(app, symbol_by_name=self.symbol_by_name)
File "/home/analytics/ENV/lib/python3.5/site-packages/celery/app/utils.py", line 345, in find_app
sym = symbol_by_name(app, imp=imp)
File "/home/analytics/ENV/lib/python3.5/site-packages/celery/bin/base.py", line 503, in symbol_by_name
return imports.symbol_by_name(name, imp=imp)
File "/home/analytics/ENV/lib/python3.5/site-packages/kombu/utils/imports.py", line 56, in symbol_by_name
module = imp(module_name, package=package, **kwargs)
File "/home/analytics/ENV/lib/python3.5/site-packages/celery/utils/imports.py", line 101, in import_from_cwd
return imp(module, package=package)
File "/home/analytics/ENV/lib/python3.5/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 665, in exec_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "/home/analytics/messages/tasks.py", line 5, in <module>
@app.tasks
TypeError: 'TaskRegistry' object is not callable
Вопрос:
Что я делаю не так?