Celery:收到未注册的类型任务

时间:2017-07-19 17:09:19

标签: python django redis celery

这是我第一次使用芹菜,而我在执行一些简单的功能时遇到了麻烦。我运行celery -A IrisOnline worker/beat -l info,它给了我未注册的类型错误。继承我的应用程序的结构:

-Iris-Online
 -IrisOnline
   -__init__.py
   -tasks.py
   -celery_app.py
   -settings.py
 -templates
 -manage.py 

settings.py

BROKER_URL = 'redis://localhost:6379'
CELERY_RESULT_BACKEND = 'redis://localhost:6379'
CELERY_ACCEPT_CONTENT = ['application/json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_TIMEZONE = 'Asia/Manila'

CELERYBEAT_SCHEDULE = {
    'execute_1_min': {
        'task': 'celery_app.printthis',
        'schedule': crontab(minute='*/1'),
        'args': (16,16)
    },
}
CELERY_IMPORTS = ("IrisOnline.celery_app","IrisOnline.tasks")

tasks.py

from celery import Celery

app = Celery('tasks',backend="redis://localhost:6379")

@app.task
def print_this():
    print("something")

celery_app.py

from django.conf import settings

# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'IrisOnline.settings')

app = Celery('tasks', broker='redis://localhost:6379/0')

# Using a string here means the worker don't have to serialize
# the configuration object to child processes.
# - namespace='CELERY' means all celery-related configuration keys
#   should have a `CELERY_` prefix.
app.config_from_object('django.conf:settings')

# Load task modules from all registered Django app configs.
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)


@app.task(bind=True)
def printsomething(self):
    print('this')

0 个答案:

没有答案
相关问题