Created
December 16, 2017 21:15
-
-
Save bencleary/0cbfb8844c7ebe3e172b7fe32ef76954 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import absolute_import, unicode_literals | |
from celery import shared_task | |
from django.utils import timezone | |
from .models import * | |
@shared_task | |
def add(x, y): | |
return x + y | |
class EmailSendError(Exception): | |
pass | |
@shared_task | |
def send_email(id): | |
email = EmailQueue.objects.get(pk=id) | |
try: | |
# send logic would allow for success or fail result, for this example just print out to console | |
print("Email sent to - {0}".format(email.auction.owner.email)) | |
update_bid_row(email.bid) | |
email.delete() | |
except: | |
raise EmailSendError("Email could not send for reason XYZ") | |
def update_bid_row(bid): | |
bid.email_sent = True | |
bid.email_sent_time = timezone.now() | |
bid.save() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment