Celery:未配置结果后端?

10

我想在命令行中检查celery的结果,但是出现了No Result Backend Configured错误。我已经将redis设置为我的结果后端,但是现在不知所措。

我的celery应用程序的设置如下:

qflow/celery.py:

os.environ.setdefault('CELERY_CONFIG_MODULE', 'qflow.celeryconfig')

app = Celery(
    'qflow',
    include=['qflow.tasks']
)
app.config_from_envvar('CELERY_CONFIG_MODULE')

config模块(qflow/celeryconfig.py)的内容如下:

broker_url = 'redis://localhost:6379/0'
result_backend = 'redis://localhost:6379/0'
result_persistent = True
task_result_expires = None
send_events = True

芹菜工人启动正常:

$ celery -A qflow worker -E -l info

 -------------- celery@james-laptop v4.0.2 (latentcall)
---- **** ----- 
--- * ***  * -- Linux-4.8.0-52-generic-x86_64-with-debian-stretch-sid 2017-07-21 14:22:34
-- * - **** --- 
- ** ---------- [config]
- ** ---------- .> app:         qflow:0x7fcbde317f28
- ** ---------- .> transport:   redis://localhost:6379/0
- ** ---------- .> results:     redis://localhost:6379/0
- *** --- * --- .> concurrency: 4 (prefork)
-- ******* ---- .> task events: ON
--- ***** ----- 
 -------------- [queues]
                .> celery           exchange=celery(direct) key=celery

看起来表明结果已经配置。

我从我的基于falcon和运行于gunicorn的webapp中导入任务并启动它们,但当我尝试在命令行中查询时使用celery result <task_id>, 我得到以下提示:

Traceback (most recent call last):
  File "/home/james/miniconda3/envs/qflow/bin/celery", line 11, in <module>
    load_entry_point('celery', 'console_scripts', 'celery')()
  File "/home/james/miniconda3/envs/qflow/lib/python3.6/site-packages/celery/__main__.py", line 14, in main
    _main()
  File "/home/james/miniconda3/envs/qflow/lib/python3.6/site-packages/celery/bin/celery.py", line 326, in main
    cmd.execute_from_commandline(argv)
  File "/home/james/miniconda3/envs/qflow/lib/python3.6/site-packages/celery/bin/celery.py", line 488, in execute_from_commandline
    super(CeleryCommand, self).execute_from_commandline(argv)))
  File "/home/james/miniconda3/envs/qflow/lib/python3.6/site-packages/celery/bin/base.py", line 281, in execute_from_commandline
    return self.handle_argv(self.prog_name, argv[1:])
  File "/home/james/miniconda3/envs/qflow/lib/python3.6/site-packages/celery/bin/celery.py", line 480, in handle_argv
    return self.execute(command, argv)
  File "/home/james/miniconda3/envs/qflow/lib/python3.6/site-packages/celery/bin/celery.py", line 412, in execute
    ).run_from_argv(self.prog_name, argv[1:], command=argv[0])
  File "/home/james/miniconda3/envs/qflow/lib/python3.6/site-packages/celery/bin/base.py", line 285, in run_from_argv
    sys.argv if argv is None else argv, command)
  File "/home/james/miniconda3/envs/qflow/lib/python3.6/site-packages/celery/bin/base.py", line 368, in handle_argv
    return self(*args, **options)
  File "/home/james/miniconda3/envs/qflow/lib/python3.6/site-packages/celery/bin/base.py", line 244, in __call__
    ret = self.run(*args, **kwargs)
  File "/home/james/miniconda3/envs/qflow/lib/python3.6/site-packages/celery/bin/result.py", line 40, in run
    value = task_result.get()
  File "/home/james/miniconda3/envs/qflow/lib/python3.6/site-packages/celery/result.py", line 189, in get
    on_message=on_message,
  File "/home/james/miniconda3/envs/qflow/lib/python3.6/site-packages/celery/backends/base.py", line 466, in wait_for_pending
    no_ack=no_ack,
  File "/home/james/miniconda3/envs/qflow/lib/python3.6/site-packages/celery/backends/base.py", line 772, in _is_disabled
    raise NotImplementedError(E_NO_BACKEND.strip())
NotImplementedError: No result backend is configured.
Please see the documentation for more information.

我正在使用Linux操作系统 (4.8.0-52-generic)


在初始化celery app时尝试设置代理。应该像这样:app = Celery('qflow', include=['qflow.tasks'], broker='redis://localhost:6379/0')。并检查您的Redis连接。 - Danila Ganchar
你启动了Celery Beat吗? - Искрен Станиславов
1个回答

1

如果在命令行参数中没有提供应用程序名称,celery将无法获取提供的配置值。因此,它使用默认的配置值,并且默认情况下后端被禁用。如果任何人仍然遇到此问题,请尝试使用以下命令调用:

celery -A qflow result <task_id>


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接