Skip to content

Tasks

hypha.apply.activity.tasks

app module-attribute

app = Celery('tasks')

send_mail

send_mail(subject, message, from_address, recipients, logs=None)
Source code in hypha/apply/activity/tasks.py
def send_mail(subject, message, from_address, recipients, logs=None):
    if settings.EMAIL_SUBJECT_PREFIX:
        subject = str(settings.EMAIL_SUBJECT_PREFIX) + str(subject)
    # Convenience method to wrap the tasks and handle the callback
    send_mail_task.apply_async(
        kwargs={
            "subject": subject,
            "body": message,
            "from_email": from_address,
            "to": recipients,
        },
        link=update_message_status.s([log.pk for log in logs]),
    )

send_mail_task

send_mail_task(**kwargs)
Source code in hypha/apply/activity/tasks.py
@app.task
def send_mail_task(**kwargs):
    response = {"status": "", "id": None}
    email = EmailMessage(**kwargs)
    try:
        email.send()
    except Exception as e:
        response["status"] = "Error: " + str(e)
    else:
        try:
            return {
                "status": email.anymail_status.status.pop(),
                "id": email.anymail_status.message_id,
            }
        except AttributeError:
            response["status"] = "sent"

    return response

update_message_status

update_message_status(response, message_pks)
Source code in hypha/apply/activity/tasks.py
@app.task
def update_message_status(response, message_pks):
    from .models import Message

    messages = Message.objects.filter(pk__in=message_pks)
    messages.update(external_id=response["id"])
    messages.update_status(response["status"])