python time limit exceeded_Celery任务获取SoftTimeLimitheeded调用API

我有两个任务,我需要调用两个不同的API来发送短信和电子邮件。在

视图.py在def ...:

...

send_payment_failed_sms.delay(payment_log.id, 1)

task_send_booking_failed_email(payment_log.id, 1)

但是我总是在发送短信的任务上遇到以下错误,但是发送电子邮件的任务工作正常:

^{pr2}$

任务.py在@shared_task(bind=True, base=MyBaseClassForTask, max_retries=5, default_retry_delay=1 * 60, soft_time_limit=15,

time_limit=30)

def send_payment_failed_sms(self, payment_id, reason):

try:

try:

payload = ""

headers = {'content-type': 'application/x-www-form-urlencoded'}

url = 'https://sms-site.com/apikey=' + api_key + '&to=%s&var1=%s' % (

mobile, payment_log.id

)

response = requests.request("GET", url, data=payload, headers=headers)

response = response.json()

if response['Status'] == 'Success':

print('Sent message'), response['Details']

else:

print('Error:', response['Details'])

except ConnectionError as exc:

print('connection error @ failed sms')

raise self.retry(exc=exc)

except PaymentLog.DoesNotExist:

...

此外,它不会在最大重试次数(即5次)内重试。你能告诉我我做错了什么吗?或者,有没有更好的方法在调用API时定义任务?在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值