简体   繁体   中英

Django Celery task to continue after error/exception

I have a celery task that loops through a list of receivers to send a message. If any of the send calls fail, I dont want the celery task to exit, but instead continue with the other items in the loop.

This does not happen with task.retry(throw=False) in my case. I do see the task exiting at that point without doing blah or even iterating through the loop further.

I dont want chords or chains, it is not a parallel task execution. How can I accomplish this ?

@celery_app.task()

def send_msg_to_list():

    for recvr in Emailrecvr.objects.filter(query=obj):
        try:

            email_rv = recvr.send(msg)

        except SMTPException:

            # Dont exit the loop but continue with others 
            send_msg_to_list.retry(throw=False)

    # do some blah here
celery_app.task()
def send_msg_to_list():

    for recvr in Emailrecvr.objects.filter(query=obj):
        try:

            email_rv = recvr.send(msg)

        except SMTPException:

            # Dont exit the loop but continue with others 
            pass

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM