FlaskベースのWebアプリでセロリを使用して、その状態を監視しようとしています。私の考えは、タスクのIDをセッションに保存し、それを状態ポーリングに使用することです。
これが私のtasks.pyの内容です
from traceback import format_exc
import settings
from celery import Celery, current_task
from celery.utils.log import get_task_logger
from celery.result import AsyncResult
from nimble_auth import make_nimble_req
logger = get_task_logger(__name__)
celery = Celery('tasks')
celery.config_from_object(settings)
@celery.task
def make_work(param1, param2):
try:
# work here
current_task.update_state(state='PROGRESS', meta={'current': page, 'total': total_pages})
except StandardError:
logger.error(format_exc())
def get_asynctask(task_id):
return AsyncResult(task_id)
メインアプリのファイルweb.pyを除く
@app.route('/task_state/<task_id>')
def task_state(task_id):
return get_asynctask(task_id).state # from task.py
@app.route('/reset_task')
def reset_task():
del session['celery_task_id']
return redirect(url_for('index'))
@app.route('/run')
def run_task():
task = make_work.delay(1, 2)
session['celery_task_id'] = task.task_id
flash('Task submitted OK!')
return redirect(url_for('index'))
設定ファイル:
BROKER_URL = 'mongodb://localhost:27017/dramba'
CELERY_RESULT_BACKEND = "mongodb"
CELERY_RESULT_DBURI = 'mongodb://localhost:27017/dramba'
しかし、タスクの状態を取得しようとすると、NotImplementedError:結果のバックエンドが構成されていません。
完全なスタックトレース:
Traceback (most recent call last):
File "/Users/cleg/Projects/Venvs/Dramba/lib/python2.7/site-packages/flask/app.py", line 1701, in __call__
return self.wsgi_app(environ, start_response)
File "/Users/cleg/Projects/Venvs/Dramba/lib/python2.7/site-packages/flask/app.py", line 1689, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/Users/cleg/Projects/Venvs/Dramba/lib/python2.7/site-packages/flask/app.py", line 1687, in wsgi_app
response = self.full_dispatch_request()
File "/Users/cleg/Projects/Venvs/Dramba/lib/python2.7/site-packages/flask/app.py", line 1360, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/Users/cleg/Projects/Venvs/Dramba/lib/python2.7/site-packages/flask/app.py", line 1358, in full_dispatch_request
rv = self.dispatch_request()
File "/Users/cleg/Projects/Venvs/Dramba/lib/python2.7/site-packages/flask/app.py", line 1344, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/Users/cleg/Projects/GitHub/Dramba/dramba.py", line 13, in task_state
return get_asynctask(task_id).state
File "/Users/cleg/Projects/Venvs/Dramba/lib/python2.7/site-packages/celery/result.py", line 284, in state
return self.backend.get_status(self.id)
File "/Users/cleg/Projects/Venvs/Dramba/lib/python2.7/site-packages/celery/backends/base.py", line 490, in _is_disabled
raise NotImplementedError('No result backend configured. '
NotImplementedError: No result backend configured. Please see the documentation for more information.
私は何が間違っているのですか?