【Celery】Celery Task Status編
Task Status
参考:http://docs.celeryproject.org/en/latest/userguide/tasks.html#states
Celeryには、Taskの状態を示すStatusが定義されています。
成功時(success)・失敗時(failure)・再実行時(retry)のStatusには、Statusが変わった時に発火する処理を定義出来ます。
デフォルトのStatus
http://docs.celeryproject.org/en/latest/userguide/tasks.html#built-in-states
PENDING :実行待ち
STARTED :実行開始した(デフォルトでは報告されない) CELERY_TRACK_STARTED=Trueで、報告されるようになるようです。参考
SUCCESS :成功した
発火する処理 : Task.on_success(retval, task_id, args, kwargs)
retval – The return value of the task. task_id – Unique id of the executed task. args – Original arguments for the executed task. kwargs – Original keyword arguments for the executed task.
FAILURE :失敗した
発火する処理 :Task.on_failure(exc, task_id, args, kwargs, einfo)
exc – The exception raised by the task. task_id – Unique id of the failed task. args – Original arguments for the task that failed. kwargs – Original keyword arguments for the task that failed. einfo – ExceptionInfo instance, containing the traceback.
RETRY :再実行された
発火する処理 :Task. on_retry(exc, task_id, args, kwargs, einfo)
exc – The exception sent to retry(). task_id – Unique id of the retried task. args – Original arguments for the retried task. kwargs – Original keyword arguments for the retried task. einfo – ExceptionInfo instance, containing the traceback.
REVOKED :無効
retry
http://docs.celeryproject.org/en/latest/userguide/tasks.html#retrying
リトライ回数等、さくっと定義出来るみたいです。
今回は未実装です。
独自の Statusの作成
http://docs.celeryproject.org/en/latest/userguide/tasks.html#custom-states
独自のStatusも作成できるようです。
また、Statusはupdate_stateを呼ぶことで、変更することが出来るようです。
from celery import current_task current_task.update_state(state=HOGE)
【Celery】Celery 要件と環境編
【Celery】Celery インストール、Worker立ち上げ編
【Celery】Celery アプリ・タスクの定義編
【Celery】Celery タスクの追加とflower編
【Celery】Celery Task Status編
【Celery】Celery 結果をmysqlに格納する編
【Celery】Celery 複数サーバーでworkerを立ち上げてみる編
【Celery】Celery 感想編