我有以下代码
from utils import SendSMS
from celery.exceptions import *
@celery.task(bind=True, max_retries=3)
def send_sms(self,sms_list):
failed_items = []
for sms_item in sms_list:
status = SendSMS( **sms_item )
if status in ['Timeout','Error']:
failed_items.append( sms_item )
if len(failed_items) > 0:
raise self.retry(failed_items)
return "sms(s) send successfully."
我想重试任务,但使用不同的数据集,只有失败的项目。
我的意思是如何实现这一目标:
raise self.retry(failed_items) ?
提前致谢。
答案 0 :(得分:3)
@task()
def add(self, x, y):
if not x or not y:
try:
raise Exception("test error")
except Exception, e:
add.retry(args=[x, y], exc=e, countdown=30)
return x+y
答案 1 :(得分:0)
@celery.task(bind=True, max_retries=2)
def send_sms(self,**kwargs):
sms_list = kwargs.get("sms_list",[])
failed_items = []
for sms_item in sms_list:
status = SendSMS( **sms_item )
if status in ['Timeout','Error']:
failed_items.append( sms_item )
if len(failed_items) > 0:
exc = Exception(status)
raise self.retry( exc=exc, sms_list=failed_items)
return "sms(s) send successfully."