带有 Amazon SQS 配置的 Django-q

Posted

技术标签:

【中文标题】带有 Amazon SQS 配置的 Django-q【英文标题】:Django-q with Amazon SQS configuration 【发布时间】:2018-07-25 11:43:15 【问题描述】:

我第一次尝试配置 Django-q,使用 Amazon SQS 作为代理。

我正在使用 Python 2.7.11、Django 1.11.5、Django-q 0.9.2、boto3 1.5.28 和 django-storages 1.4.1。

我已经在我的 Django 应用程序中使用 AWS S3 和 cloudfront 几年了,因此它们配置正确。我使用 S3 和 cloudfront 提供媒体文件,而 django-whitenoise 提供 django 静态文件。

我已经为 SQS 创建了新的 IAM 用户,并给了它AmazonSQSFullAccess。 我在我的项目中使用的应用程序列表 (settings.py):

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'whitenoise.runserver_nostatic',
    'django.contrib.staticfiles',
    'django.contrib.sites',
    'django.contrib.humanize',
    'django.contrib.sitemaps',
    'utils',
    'storages',
    'my_app',
    'debug_toolbar',
    'widget_tweaks',
    'django_q',
)

按照Django-q documentation,我已经到了应该执行此命令的步骤:

python manage.py qcluster

这给了我这些错误:

pickle.PicklingError: Can't pickle <class 'boto3.resources.factory.sqs.ServiceResource'> it's not found as boto3.resources.factory.sqs.ServiceResource

还有 Django 错误:

raise AppRegistryNotReady(aren't loaded yet.") django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.

这让我很困惑,我真的不知道可能是什么问题..

更新

这是 cmd 完整的错误跟踪:

Traceback (most recent call last):
  File "manage.py", line 22, in <module>
  execute_from_command_line(sys.argv)
  File "just_a_path_to_my_app\lib\site-packages\django\core\management\__init__.py", line 364, in execute_from_command_line
    utility.execute()
  File "just_a_path_to_my_app\lib\site-packages\django\core\management\__init__.py", line 356, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "just_a_path_to_my_app\lib\site-packages\django\core\management\base.py", line 283, in run_from_argv
    self.execute(*args, **cmd_options)
  File "just_a_path_to_my_app\lib\site-packages\django\core\management\base.py", line 330, in execute
    output = self.handle(*args, **options)
  File "just_a_path_to_my_app\lib\site-packages\django_q\management\commands\qcluster.py", line 22, in handle
    q.start()
  File "just_a_path_to_my_app\lib\site-packages\django_q\cluster.py", line 54, in start
    self.sentinel.start()
  File "c:\python27\Lib\multiprocessing\process.py", line 130, in start
  self._popen = Popen(self)
  File "c:\python27\Lib\multiprocessing\forking.py", line 277, in __init__
  dump(process_obj, to_child, HIGHEST_PROTOCOL)
  File "c:\python27\Lib\multiprocessing\forking.py", line 199, in dump
  ForkingPickler(file, protocol).dump(obj)
  File "c:\python27\Lib\pickle.py", line 224, in dump
  self.save(obj)
  File "c:\python27\Lib\pickle.py", line 331, in save
  self.save_reduce(obj=obj, *rv)
  File "c:\python27\Lib\pickle.py", line 425, in save_reduce
  save(state)
  File "c:\python27\Lib\pickle.py", line 286, in save
  f(self, obj) # Call unbound method with explicit self
  File "c:\python27\Lib\pickle.py", line 655, in save_dict
  self._batch_setitems(obj.iteritems())
  File "c:\python27\Lib\pickle.py", line 687, in _batch_setitems
  save(v)
  File "c:\python27\Lib\pickle.py", line 286, in save
  f(self, obj) # Call unbound method with explicit self
  File "c:\python27\Lib\pickle.py", line 568, in save_tuple
  save(element)
  File "c:\python27\Lib\pickle.py", line 331, in save
  self.save_reduce(obj=obj, *rv)
  File "c:\python27\Lib\pickle.py", line 425, in save_reduce
  save(state)
  File "c:\python27\Lib\pickle.py", line 286, in save
  f(self, obj) # Call unbound method with explicit self
  File "c:\python27\Lib\pickle.py", line 655, in save_dict
  self._batch_setitems(obj.iteritems())
  File "c:\python27\Lib\pickle.py", line 687, in _batch_setitems
  save(v)
  File "c:\python27\Lib\pickle.py", line 331, in save
  self.save_reduce(obj=obj, *rv)
  File "c:\python27\Lib\pickle.py", line 396, in save_reduce
  save(cls)
  File "c:\python27\Lib\pickle.py", line 286, in save
  f(self, obj) # Call unbound method with explicit self
  File "c:\python27\Lib\pickle.py", line 754, in save_global
  (obj, module, name))
pickle.PicklingError: Can't pickle <class 'boto3.resources.factory.sqs.ServiceRe
source'>: it's not found as boto3.resources.factory.sqs.ServiceResource

(my_app) just_a_path_to_my_app\fakultet>Traceback (most recent call last):
  File "<string>", line 1, in <module>
File "c:\python27\Lib\multiprocessing\forking.py", line 381, in main
  self = load(from_parent)
  File "c:\python27\Lib\pickle.py", line 1384, in load
  return Unpickler(file).load()
  File "c:\python27\Lib\pickle.py", line 864, in load
  dispatch[key](self)
  File "c:\python27\Lib\pickle.py", line 1096, in load_global
  klass = self.find_class(module, name)
  File "c:\python27\Lib\pickle.py", line 1130, in find_class
  __import__(module)
  File "just_a_path_to_my_app\lib\site-packages\django_q\cluster.py", line 25, in <module>
    import tasks
  File "just_a_path_to_my_app\lib\site-packages\django_q\tasks.py", line 11, in <module>
    import cluster
  File "just_a_path_to_my_app\lib\site-packages\django_q\cluster.py", line 29, in <module>
    from django_q.models import Task, Success, Schedule
  File "just_a_path_to_my_app\lib\site-packages\django_q\models.py", line 16, in <module>
    class Task(models.Model):
  File "just_a_path_to_my_app\lib\site-packages\django\db\models\base.py", line 110, in __new__
    app_config = apps.get_containing_app_config(module)
  File "just_a_path_to_my_app\lib\site-packages\django\apps\registry.py", line 247, in get_containing_app_config
    self.check_apps_ready()
  File "just_a_path_to_my_app\lib\site-packages\django\apps\registry.py", line 125, in check_apps_ready
    raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.

【问题讨论】:

你能从错误中发布完整的堆栈跟踪吗? @markwalker_ 我已经用错误更新了我的问题。 【参考方案1】:

我不知道 django-q 有 Windows compatibility issues,所以这就是为什么我无法让它在我的 Windows 开发机器下工作的原因。在我的生产 CentOS 服务器上安装 django-q 并按照简单的配置说明进行操作后 - 一切顺利。

【讨论】:

很高兴听到您找到了解决方案。你应该把你的答案标记为正确,这样这个问题就会留在未回答的问题列表中

以上是关于带有 Amazon SQS 配置的 Django-q的主要内容,如果未能解决你的问题,请参考以下文章

Amazon-SQS + Django-Celery 创建了数千个队列(每条消息一个队列)

Amazon SQS 如何控制重试次数

无法访问 Amazon SQS - InvalidClientTokenId

Amazon SQS“接收计数”只会增加

Amazon SQS 死信队列:真的是死信还是毒药?

Amazon MQ 和 SQS 有啥区别?