我有以下代码
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) ?
预先感谢。
@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
@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."