LoginSignup
1
1

More than 3 years have passed since last update.

celeryconfig.pyを使わずにCeleryのbackendを指定するときの注意点

Posted at

いやceleryconfig.pyを使えっていう話なんですが、直接指定する場合の注意点について書きます。

結論

result_backendではなくbackendを指定しましょう。

app = Celery('run', broker='redis://localhost:6379/0', backend='redis://localhost:6379/1')

result_backendbackend

Celeryのドキュメントなんかを見てると、処理したタスクの結果を指定するにはresult_backendを指定するように記述があります。
celeryconfig.pyを使う場合にはこれで問題無いですが、上記のようにコード中に直接記述する場合はresult_backendではなくbackendを指定する必要があります。

設定してるはずなのに結果が出力されないなーとしばらく悩んでいたんですが、githubのCeleryクラスを見ると、コンストラクタでresult_backendなんて引数は受け取ってくれないことが判明しました。

base.py
def __init__(self, main=None, loader=None, backend=None,
                 amqp=None, events=None, log=None, control=None,
                 set_as_current=True, tasks=None, broker=None, include=None,
                 changes=None, config_source=None, fixups=None, task_cls=None,
                 autofinalize=True, namespace=None, strict_typing=True,
                 **kwargs):

こんなところで詰まるのは私だけかもしれませんが、メモとして残しておきます。
誰かの役に立てば幸いです。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1