这是我第一次使用芹菜,而我在执行一些简单的功能时遇到了麻烦。我运行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')