At work i've got quite of an interesting project which was sending an email while attaching 2 reports that can be quite process intensive. So, since the Django app already includes Celery so i decided to take advantage of it.

The general algorithm looks something along like:

• Generate Report A
• Generate Report B
• send emaill

The tricky part about this is that we can do 2 things at once but we cannot send the email until the 3 first algorithm execution steps have been completed so! thanks to celery i was able to make this happens as following:

from celery.app import task
from celery import group

def generate_report_a(report_a_data):
url = None
... # logic to generate the report and retrieve the url
return url

def generate_report_g(report_b_data):
url = None
... # logic to generate the report and retrieve the url
return url

def send_email_content(reports, email_data):
report_a, report_b = reports
from_email = None
to_email = None
subject = None
body = None

... # logic to parse email
... # send email with both reports

# algorithm execution with celery