简体   繁体   English

celery :收到类型为“celery_deploy.tasks._stocks”的未注册任务

[英]celery : Received unregistered task of type 'celery_deploy.tasks._stocks'

When I run celery as below: celery -A bookmarks worker -l INFO当我按如下方式运行 celery 时: celery -A bookmarks worker -l INFO

it returned:它返回:

[2020-11-10 23:14:21,649: ERROR/MainProcess] Received unregistered task of type 'celery_deploy.tasks._stocks'.
The message has been ignored and discarded.
Did you remember to import the module containing this task?
Or maybe you're using relative imports?
KeyError: 'celery_deploy.tasks._stocks'

my celery.py in project bookmarks directory(where the Django project settings.py is):我在项目书签目录中的 celery.py(Django 项目 settings.py 所在的位置):

from __future__ import  absolute_import, unicode_literals
import os
from celery import Celery, platforms
from datetime import timedelta
from . import settings
BROKER_URL = 'redis://localhost:6379/0'
BACKEND_URL = 'redis://localhost:6379/1'
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'bookmarks.settings')
app = Celery('bookmarks', backend=BACKEND_URL, broker=BROKER_URL)
app.config_from_object('django.conf:settings', namespace='CELERY')
app.autodiscover_tasks(lambda : settings.INSTALLED_APPS)
platforms.C_FORCE_ROOT = True

app.conf.update(
    CELERY_ACKS_LATE = True,
    CELERY_ACCEPT_CONTENT = ['json'],
    CELERY_FORCE_EXECV = True,
    CELERY_CONCURRENCY = 4,
    CELERYD_MAX_TASKS_PER_CHILD = 10,
    CELERYBEAT_SCHEDULE = {
        'get_stock_': {
            'task': 'celery_deploy.tasks._stocks',
            'schedule': timedelta(seconds=21),
        },
    },
)

@app.task(bind = True)
def debug_task(self):
    print('Request: {0!r}'.format(self.request))

My tasks.py in Django app celery_deploy:我在 Django 应用 celery_deploy 中的 tasks.py:

from __future__ import absolute_import
from celery import shared_task
from django.core.cache import cache
from urllib.request import urlopen
from bookmarks.celery import app
import json
import redis

apibase = "https://financialmodelingprep.com/api/v3/"
apikey = "[KEY]"
exchange_open_day = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri']
json_parsed = {}
CACHE_TIMEOUT = 60*60

@app.task
def _stocks():
    url = apibase + "quotes/nyse" + "?" + apikey
    response = urlopen(url)
    stocks_parsed = json.loads(response.read().decode("utf-8"))
    for _object in stocks_parsed:
        cache.set(_object['symbol'], _object['price'], CACHE_TIMEOUT)

I read many questions similar to mine, but still cannot figure out.我阅读了许多与我类似的问题,但仍然无法弄清楚。

What should I do to fix it?Thank you.我该怎么做才能修复它?谢谢。

The error is likely to do with your Instantiaion .该错误可能与您的Instantiaion 有关 Assuming you are trying an App-Wide usage , then the following will not work since you are required to set the task_cls attribute.假设您正在尝试App-Wide usage ,那么以下将不起作用,因为您需要设置task_cls属性。

Here这里

app = Celery('bookmarks', backend=BACKEND_URL, broker=BROKER_URL)

The bookmarks refers to your directory but is failing to import the required method at runtime. bookmarks指向您的目录,但无法在运行时导入所需的方法。

Can you change the line to include your filename, eg您可以更改该行以包含您的文件名,例如

app = Celery('bookmarks.tasks', backend=BACKEND_URL, broker=BROKER_URL)

This should hopefully solve the problem.这应该有望解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 芹菜“收到未注册类型的任务” - Celery “Received unregistered task of type” Django Celery收到类型为“appname.tasks.add”的未注册任务 - Django Celery Received unregistered task of type 'appname.tasks.add' 基本 Celery 任务未运行(错误/MainProcess] 收到“app.celery_tasks.test_task”类型的未注册任务) - Basic Celery task not runnning (ERROR/MainProcess] Received unregistered task of type 'app.celery_tasks.test_task') 芹菜“收到未注册的任务” - Celery “received unregistered task” 芹菜:接收类型为未注册的任务<AsyncResult: [hash]> - Celery: Received unregistered task of type <AsyncResult: [hash]> 在Flask-Celery中收到类型为“”的未注册任务 - Received unregistered task of type “” in Flask-Celery Celery Redis返回“已接收未注册的类型任务” - Celery Redis returns “Received unregistered task of type” Celery 收到未注册类型的任务(运行示例) - Celery Received unregistered task of type (run example) Pytest 与 Celery 任务有效,但显示“消费者错误:收到 X 类型的未注册任务” - Pytest with Celery tasks works but shows "ERROR in consumer: Received unregistered task of type X" 注册任务时,KeyError 在 celery 上收到类型为“”的未注册任务 - KeyError Received unregistered task of type '' on celery while task is registered
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM