芹菜在get_scheduler上击败TypeError

时间:2017-04-24 16:35:15

标签: python django celery

尝试使用Supervisor设置Celery正在运行Python3.5Django==1.10.2celery==4.0.2,但我在site-packages/celery/beat上收到此错误

Traceback (most recent call last):
  File "/home/user_one/venv/app_one/bin/celery", line 11, in <module>
    sys.exit(main())
  File "/home/user_one/venv/app_one/lib/python3.5/site-packages/celery/__main__.py", line 14, in main
    _main()
  File "/home/user_one/venv/app_one/lib/python3.5/site-packages/celery/bin/celery.py", line 326, in main
    cmd.execute_from_commandline(argv)
  File "/home/user_one/venv/app_one/lib/python3.5/site-packages/celery/bin/celery.py", line 488, in execute_from_commandline
    super(CeleryCommand, self).execute_from_commandline(argv)))
  File "/home/user_one/venv/app_one/lib/python3.5/site-packages/celery/bin/base.py", line 281, in execute_from_commandline
    return self.handle_argv(self.prog_name, argv[1:])
  File "/home/user_one/venv/app_one/lib/python3.5/site-packages/celery/bin/celery.py", line 480, in handle_argv
    return self.execute(command, argv)
  File "/home/user_one/venv/app_one/lib/python3.5/site-packages/celery/bin/celery.py", line 412, in execute
    ).run_from_argv(self.prog_name, argv[1:], command=argv[0])
  File "/home/user_one/venv/app_one/lib/python3.5/site-packages/celery/bin/base.py", line 285, in run_from_argv
    sys.argv if argv is None else argv, command)
  File "/home/user_one/venv/app_one/lib/python3.5/site-packages/celery/bin/base.py", line 368, in handle_argv
    return self(*args, **options)
  File "/home/user_one/venv/app_one/lib/python3.5/site-packages/celery/bin/base.py", line 244, in __call__
    ret = self.run(*args, **kwargs)
  File "/home/user_one/venv/app_one/lib/python3.5/site-packages/celery/bin/beat.py", line 107, in run
    return beat().run()
  File "/home/user_one/venv/app_one/lib/python3.5/site-packages/celery/apps/beat.py", line 79, in run
    self.start_scheduler()
  File "/home/user_one/venv/app_one/lib/python3.5/site-packages/celery/apps/beat.py", line 98, in start_scheduler
    print(self.banner(service))
  File "/home/user_one/venv/app_one/lib/python3.5/site-packages/celery/apps/beat.py", line 120, in banner
    c.reset(self.startup_info(service))),
  File "/home/user_one/venv/app_one/lib/python3.5/site-packages/celery/apps/beat.py", line 130, in startup_info
    scheduler = service.get_scheduler(lazy=True)
  File "/home/user_one/venv/app_one/lib/python3.5/site-packages/celery/beat.py", line 567, in get_scheduler
    lazy=lazy,
TypeError: 'module' object is not callable

应用/ settings.py

BROKER_URL = 'redis://:{}@{}:{}/{}'.format(redis_pass, redis_host, redis_port, redis_db)
CELERY_RESULT_BACKEND = 'redis://:{}@{}:{}/{}'.format(redis_pass, redis_host, redis_port, redis_celery_results_db)
CELERY_ACCEPT_CONTENT = ['application/json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'

应用/ celery.py

from __future__ import absolute_import
import os
from celery import Celery
from django.conf import settings
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'app_one.settings')
cel_app = Celery('app_one')
cel_app.config_from_object('django.conf:settings')
cel_app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
@cel_app.task(bind=True)
def debug_task(self):
    print('Request: {0!r}'.format(self.request))

我之前在其他项目中成功使用过Celery,但没有使用Django。我已将设置设为specified here。我可以错过什么吗?

1 个答案:

答案 0 :(得分:0)

所有邪恶的根源都在主管配置文件中,即 /etc/supervisor/conf.d/celer_beat.conf

command=/home/user_one/venv/app_one/bin/celery -A app_one beat --loglevel=INFO -S django

-S django指的是我没有使用的django_celery_beat。所以这被改为:

command=/home/user_one/venv/app_one/bin/celery -A app_one beat -s /home/user_one/apps/app_one/celerybeat-schedule --loglevel=INFO

这样芹菜就可以使用应用程序目录中的文件来跟踪计划,即/home/user_one/apps/app_one/目录。