我正在尝试将celery 4.2版本集成到django项目中。根据文档,我已经在 init .py和celery.py中进行了更改,但是当我使用以下方法运行celery时:
python -m celery -A instaguide beat -l debug
我在下面得到了例外。我不确定缺少了什么。我在project.settings中定义的唯一CELERY_设置是CELERY_BROKER_URL,它不会抱怨没有连接到代理。因此,我在自己的设置或其他地方都缺少了其他东西。有任何线索吗?
celery-worker | k (most recent call last):
celery-worker | File "/usr/local/lib/python2.7/runpy.py", line 174, in _run_module_as_main
celery-worker | "__main__", fname, loader, pkg_name)
celery-worker | File "/usr/local/lib/python2.7/runpy.py", line 72, in _run_code
celery-worker | exec code in run_globals
celery-worker | File "/usr/local/lib/python2.7/site-packages/celery/__main__.py", line 20, in <module>
celery-worker | main()
celery-worker | File "/usr/local/lib/python2.7/site-packages/celery/__main__.py", line 16, in main
celery-worker | _main()
celery-worker | File "/usr/local/lib/python2.7/site-packages/celery/bin/celery.py", line 322, in main
celery-worker | cmd.execute_from_commandline(argv)
celery-worker | File "/usr/local/lib/python2.7/site-packages/celery/bin/celery.py", line 496, in execute_from_commandline
celery-worker | super(CeleryCommand, self).execute_from_commandline(argv)))
celery-worker | File "/usr/local/lib/python2.7/site-packages/celery/bin/base.py", line 275, in execute_from_commandline
celery-worker | return self.handle_argv(self.prog_name, argv[1:])
celery-worker | File "/usr/local/lib/python2.7/site-packages/celery/bin/celery.py", line 488, in handle_argv
celery-worker | return self.execute(command, argv)
celery-worker | File "/usr/local/lib/python2.7/site-packages/celery/bin/celery.py", line 420, in execute
celery-worker | ).run_from_argv(self.prog_name, argv[1:], command=argv[0])
celery-worker | File "/usr/local/lib/python2.7/site-packages/celery/bin/worker.py", line 223, in run_from_argv
celery-worker | return self(*args, **options)
celery-worker | File "/usr/local/lib/python2.7/site-packages/celery/bin/base.py", line 238, in __call__
celery-worker | ret = self.run(*args, **kwargs)
celery-worker | File "/usr/local/lib/python2.7/site-packages/celery/bin/worker.py", line 257, in run
celery-worker | **kwargs)
celery-worker | File "/usr/local/lib/python2.7/site-packages/celery/worker/worker.py", line 96, in __init__
celery-worker | self.app.loader.init_worker()
celery-worker | File "/usr/local/lib/python2.7/site-packages/celery/loaders/base.py", line 114, in init_worker
celery-worker | self.import_default_modules()
celery-worker | File "/usr/local/lib/python2.7/site-packages/celery/loaders/base.py", line 108, in import_default_modules
celery-worker | raise response
celery-worker | celery.schedules.ParseException: empty filter
答案 0 :(得分:1)
我发现了问题所在。如果使用的是默认节拍计划程序,则需要使用至少一项计划任务来定义节拍计划程序配置。否则,如果使用数据库调度程序,则需要使用django-celery-beat来创建调度并将其存储在数据库中。因此,一个人至少需要有1个条目才能执行可重复的任务。另外@periodic_task批注已弃用,将在celery-5中删除,它似乎不起作用。
app.conf.beat_schedule = {
# Executes every minute
'add-every-monday-morning': {
'task': 'users.tasks.test_task',
'schedule': crontab(hour="*", minute="*"),
'args': (),
},
}