André
André

Reputation: 25554

Django-Celery - How to know when a subtask has been completed?

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".

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.

This is my 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.', '[email protected]',
        ['[email protected]'], 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?

Best Regards,

Upvotes: 1

Views: 385

Answers (2)

UnLiMiTeD
UnLiMiTeD

Reputation: 1040

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

more info here

Upvotes: 0

Related Questions