问题描述
我使用 Django 2.2 和 Celery 来处理周期性任务
我有以下任务配置
@celery.task(name='payments.recheck_payment_status')
def recheck_payment_status(payment_id):
"""
Recheck payment status
:param payment_id: Payment id for which recheck the status
:return:
"""
logger.info('Checking status for payment %s' % payment_id)
payment = Payment.objects.get(id=payment_id)
if timezone.now() > payment.created + timedelta(days=1):
logger.info('Payment done is more than 1 day. Sending email to the admin')
send_incomplete_payment_email.apply_async(args=(payment_id,))
return
if not payment.completed:
logger.info('Payment status is incomplete. Checking payment status')
payment_ = payment.recheck_payment()
if payment_.completed:
order = payment.order
order.external_reference = payment.external_reference
order.save()
if not payment_.completed:
logger.info('Payment %s is not completed yet.' % payment_id)
recheck_payment_status.apply_async(
args=(payment.id,),countdown=1800
)
任务被调用
recheck_payment_status.apply_async(args=(payment_id,countdown=300)
对于一些在 300 秒后未能检查的付款,一次又一次地重新排队到 1800 秒。
但是过去的队列没有清空,任务send_incomplete_payment_email
由于之前调度的任务被执行了多次。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)