Celery:收到类型' custom_app.tasks.function'?的未注册任务

时间:2018-06-03 15:16:41

标签: python django rabbitmq celery

在我的Django项目中,我使用Celery 4 + RabbitMQ。我想在自定义amount_counting应用程序中运行profile任务。下一个代码引发错误。怎么解决?似乎芹菜没有看到这个任务。

我用: 芹菜== 4.1.1 Django的== 1.11.5

  1. 我先使用下一个命令:
  2. celery -A EnjoyJumping beat -l info

    1. 在终端我看到:
    2. [2018-06-03 21:03:41,963: INFO/MainProcess] Scheduler: Sending due task amount-counting (profile.tasks.amount_counting)

      1. 然后我使用命令:
      2. celery -A EnjoyJumping worker -l info

        1. 在终端我看到错误:
        2. enter image description here

          celery.py:

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

          settings.py:

          CELERY_BROKER_URL = 'amqp://localhost'
          CELERY_RESULT_BACKEND = 'amqp://localhost'
          CELERY_ACCEPT_CONTENT = ['application/json']
          CELERY_RESULT_SERIALIZER = 'json'
          CELERY_TASK_SERIALIZER = 'json'
          CELERY_TIMEZONE = 'Asia/Almaty'
          CELERY_BEAT_SCHEDULE = {
              "amount-counting": {
                  "task": "profile.tasks.amount_counting",
                  "schedule": 30.0,
              },
          }
          CELERY_IMPORTS = (
              "profile",
          )
          

          配置文件/ tasks.py:

          from __future__ import absolute_import, unicode_literals
          from celery import task
          
          
          @task()
          def amount_counting():
              # some code
          

0 个答案:

没有答案
相关问题