我已经通过redis经纪人为django设置了芹菜。在本地一切都很好,但是在部署后登录heroku实例时,出现此错误:
ModuleNotFoundError: No module named 'app'
这是我的celery.py,它位于我的项目文件夹project / project / celery.py的根目录中:
import os
from celery import Celery
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "AutomatedInterview.settings")
app = Celery("AutomatedInterview")
app.config_from_object("django.conf:settings", namespace="CELERY")
app.autodiscover_tasks()
我的init.py在同一目录中:
from __future__ import absolute_import, unicode_literals
# This will make sure the app is always imported when
# Django starts so that shared_task will use this app.
from .celery import app as celery_app
__all__ = ('celery_app',)
我的个人档案:
release: python manage.py migrate
web: gunicorn AutomatedInterview.wsgi
worker: celery worker -A AutomatedInterview -l info
运行命令heroku logs -t -p worker
后的完整日志
2020-06-18T19:11:38.697329+00:00 app[worker.1]: Traceback (most recent call last):
2020-06-18T19:11:38.697361+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/kombu/utils/objects.py", line 42, in __get__
2020-06-18T19:11:38.697485+00:00 app[worker.1]: return obj.__dict__[self.__name__]
2020-06-18T19:11:38.697488+00:00 app[worker.1]: KeyError: 'data'
2020-06-18T19:11:38.697509+00:00 app[worker.1]:
2020-06-18T19:11:38.697509+00:00 app[worker.1]: During handling of the above exception, another exception occurred:
2020-06-18T19:11:38.697510+00:00 app[worker.1]:
2020-06-18T19:11:38.697510+00:00 app[worker.1]: Traceback (most recent call last):
2020-06-18T19:11:38.697513+00:00 app[worker.1]: File "/app/.heroku/python/bin/celery", line 11, in <module>
2020-06-18T19:11:38.697621+00:00 app[worker.1]: sys.exit(main())
2020-06-18T19:11:38.697624+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/celery/__main__.py", line 16, in main
2020-06-18T19:11:38.697747+00:00 app[worker.1]: _main()
2020-06-18T19:11:38.697749+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/celery/bin/celery.py", line 322, in main
2020-06-18T19:11:38.697990+00:00 app[worker.1]: cmd.execute_from_commandline(argv)
2020-06-18T19:11:38.697992+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/celery/bin/celery.py", line 495, in execute_from_commandline
2020-06-18T19:11:38.698486+00:00 app[worker.1]: super(CeleryCommand, self).execute_from_commandline(argv)))
2020-06-18T19:11:38.698491+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/celery/bin/base.py", line 305, in execute_from_commandline
2020-06-18T19:11:38.698741+00:00 app[worker.1]: return self.handle_argv(self.prog_name, argv[1:])
2020-06-18T19:11:38.698747+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/celery/bin/celery.py", line 487, in handle_argv
2020-06-18T19:11:38.699125+00:00 app[worker.1]: return self.execute(command, argv)
2020-06-18T19:11:38.699130+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/celery/bin/celery.py", line 419, in execute
2020-06-18T19:11:38.699591+00:00 app[worker.1]: ).run_from_argv(self.prog_name, argv[1:], command=argv[0])
2020-06-18T19:11:38.699596+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/celery/bin/worker.py", line 221, in run_from_argv
2020-06-18T19:11:38.699918+00:00 app[worker.1]: *self.parse_options(prog_name, argv, command))
2020-06-18T19:11:38.699953+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/celery/bin/base.py", line 428, in parse_options
2020-06-18T19:11:38.700336+00:00 app[worker.1]: self.parser = self.create_parser(prog_name, command)
2020-06-18T19:11:38.700369+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/celery/bin/base.py", line 444, in create_parser
2020-06-18T19:11:38.700796+00:00 app[worker.1]: self.add_arguments(parser)
2020-06-18T19:11:38.700830+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/celery/bin/worker.py", line 278, in add_arguments
2020-06-18T19:11:38.701211+00:00 app[worker.1]: default=conf.worker_state_db,
2020-06-18T19:11:38.701244+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/celery/utils/collections.py", line 134, in __getattr__
2020-06-18T19:11:38.701471+00:00 app[worker.1]: return self[k]
2020-06-18T19:11:38.701503+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/celery/utils/collections.py", line 444, in __getitem__
2020-06-18T19:11:38.701893+00:00 app[worker.1]: return getitem(k)
2020-06-18T19:11:38.701925+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/celery/utils/collections.py", line 287, in __getitem__
2020-06-18T19:11:38.702238+00:00 app[worker.1]: return mapping[_key]
2020-06-18T19:11:38.702270+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/collections/__init__.py", line 987, in __getitem__
2020-06-18T19:11:38.703011+00:00 app[worker.1]: if key in self.data:
2020-06-18T19:11:38.703043+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/kombu/utils/objects.py", line 44, in __get__
2020-06-18T19:11:38.703212+00:00 app[worker.1]: value = obj.__dict__[self.__name__] = self.__get(obj)
2020-06-18T19:11:38.703243+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/celery/app/base.py", line 141, in data
2020-06-18T19:11:38.703468+00:00 app[worker.1]: return self.callback()
2020-06-18T19:11:38.703499+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/celery/app/base.py", line 954, in _finalize_pending_conf
2020-06-18T19:11:38.704209+00:00 app[worker.1]: conf = self._conf = self._load_config()
2020-06-18T19:11:38.704242+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/celery/app/base.py", line 964, in _load_config
2020-06-18T19:11:38.704992+00:00 app[worker.1]: self.loader.config_from_object(self._config_source)
2020-06-18T19:11:38.705025+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/celery/loaders/base.py", line 131, in config_from_object
2020-06-18T19:11:38.705245+00:00 app[worker.1]: self._conf = force_mapping(obj)
2020-06-18T19:11:38.705290+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/celery/utils/collections.py", line 54, in force_mapping
2020-06-18T19:11:38.705460+00:00 app[worker.1]: if isinstance(m, (LazyObject, LazySettings)):
2020-06-18T19:11:38.705477+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/utils/functional.py", line 256, in inner
2020-06-18T19:11:38.705764+00:00 app[worker.1]: self._setup()
2020-06-18T19:11:38.705782+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/conf/__init__.py", line 66, in _setup
2020-06-18T19:11:38.705957+00:00 app[worker.1]: self._wrapped = Settings(settings_module)
2020-06-18T19:11:38.705974+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/conf/__init__.py", line 157, in __init__
2020-06-18T19:11:38.706227+00:00 app[worker.1]: mod = importlib.import_module(self.SETTINGS_MODULE)
2020-06-18T19:11:38.706228+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/importlib/__init__.py", line 126, in import_module
2020-06-18T19:11:38.706425+00:00 app[worker.1]: return _bootstrap._gcd_import(name[level:], package, level)
2020-06-18T19:11:38.706429+00:00 app[worker.1]: File "<frozen importlib._bootstrap>", line 994, in _gcd_import
2020-06-18T19:11:38.706584+00:00 app[worker.1]: File "<frozen importlib._bootstrap>", line 971, in _find_and_load
2020-06-18T19:11:38.706679+00:00 app[worker.1]: File "<frozen importlib._bootstrap>", line 941, in _find_and_load_unlocked
2020-06-18T19:11:38.706773+00:00 app[worker.1]: File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
2020-06-18T19:11:38.706864+00:00 app[worker.1]: File "<frozen importlib._bootstrap>", line 994, in _gcd_import
2020-06-18T19:11:38.706965+00:00 app[worker.1]: File "<frozen importlib._bootstrap>", line 971, in _find_and_load
2020-06-18T19:11:38.707055+00:00 app[worker.1]: File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
2020-06-18T19:11:38.707154+00:00 app[worker.1]: ModuleNotFoundError: No module named 'app'
我真的不知道这个模块是指什么或它来自哪里。我在celery.py中使用的app
直接在文档之外。
任何东西对任何人都突出吗?