0
我想retry
(official doc)引發異常時的任務。芹菜允許通過使用形式self.retry(...)
芹菜send_task和異常時重試
現在,我不知道如何用戶self
因爲我有一個沒有任何類的功能。
我的代碼是這樣的
.. imports ...
app = Celery('elasticcelery')
@app.task(name='rm_doc')
def rm_doc(schema_id, id):
es = Elasticsearch(es_ip)
try:
res = es.delete(schema_id, 'doc', id)
except NotFoundError as e:
<here goes the retry>
而且它以這種方式從另一個服務叫做:
app_celery = Celery('celeryelastic')
app_celery.config_from_object('django.conf:settings')
app_celery.send_task('rm_doc', kwargs={"schema_id": schema_id, "id": document_id},)
現在
,我要補充的self.retry
但在我的方法沒有self
。
我該如何繼續?
PS:我嘗試添加self
作爲參數,但是這樣做失敗了,因爲當第一次從遠程調用任務時沒有映射。