Django-Celery - 如何知道子任务何时完成?

时间:2021-12-18 21:09:49

I'm using Django-Celery-Email. This app will send a task to send an e-mail with the regular "from django.core.mail import send_mail".

我正在使用Django-Celery-Email。此应用程序将发送一个任务,以发送常规“来自django.core.mail import send_mail”的电子邮件。

I have wrote a task that will call the send_mail task, but I need to when when the subtask is done to do an update in the database.

我编写了一个将调用send_mail任务的任务,但是我需要在子任务完成时在数据库中进行更新。

This is my tasks.py

这是我的tasks.py

from celery import task


@task()
def send_ad_contact_email():
    from django.core.mail import send_mail

    # Send the e.mail
    send_mail('test subject', 'Here is the message.', 'somemail@gmail.com',
        ['tosomemail@gmail.com'], fail_silently=False)

    # Update the email status on the model
    # How can I know when send_mail(celery task) is done?

How can I know when send_mail(celery task) is done?

我怎么知道send_mail(芹菜任务)什么时候完成?

Best Regards,

2 个解决方案

#1


1  

You might need to use a chord. http://docs.celeryproject.org/en/latest/userguide/canvas.html?highlight=taskset#chords

您可能需要使用和弦。 http://docs.celeryproject.org/en/latest/userguide/canvas.html?highlight=taskset#chords

#2


0  

task_id = request.GET['task_id']
res = AsyncResult(task_id)
result = res.result

more info here

更多信息在这里

#1


1  

You might need to use a chord. http://docs.celeryproject.org/en/latest/userguide/canvas.html?highlight=taskset#chords

您可能需要使用和弦。 http://docs.celeryproject.org/en/latest/userguide/canvas.html?highlight=taskset#chords

#2


0  

task_id = request.GET['task_id']
res = AsyncResult(task_id)
result = res.result

more info here

更多信息在这里