Skip to content

Commit

Permalink
Rigging up the email to the celery debug_task again.
Browse files Browse the repository at this point in the history
  • Loading branch information
joshSzep committed Jul 22, 2024
1 parent f5af359 commit 3397298
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
24 changes: 20 additions & 4 deletions hangul_tutor/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import time

import celery
from django.core.mail import send_mail


# Set the default Django settings module for the 'celery' program.
Expand All @@ -26,7 +27,22 @@

@app.task(bind=True, ignore_result=True)
def debug_task(self):
logger.info("Starting debug task")
time.sleep(5)
logger.info("Debug task finished")
logger.debug(f"Request: {self.request!r}")
# Send email
send_mail(
subject="Debug Task Started",
message="The debug task has started.",
from_email=None, # Use default from email
recipient_list=["[email protected]"],
fail_silently=False,
)

time.sleep(30)

# Send email
send_mail(
subject="Debug Task Finished",
message="The debug task has finished.",
from_email=None, # Use default from email
recipient_list=["[email protected]"],
fail_silently=False,
)
8 changes: 8 additions & 0 deletions hangul_tutor/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,14 @@
CELERY_TASK_TIME_LIMIT = 30 * 60
CELERY_TASK_SOFT_TIME_LIMIT = 20 * 60

EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
EMAIL_HOST = os.environ.get("EMAIL_HOST")
EMAIL_PORT = int(os.environ.get("EMAIL_PORT", -1))
EMAIL_USE_TLS = os.environ.get("EMAIL_USE_TLS", "false").lower() == "true"
EMAIL_HOST_USER = os.environ.get("EMAIL_HOST_USER")
EMAIL_HOST_PASSWORD = os.environ.get("EMAIL_HOST_PASSWORD")
DEFAULT_FROM_EMAIL = os.environ.get("DEFAULT_FROM_EMAIL")

AUTHENTICATION_BACKENDS = [
# Needed to login by username in Django admin, regardless of `allauth`
"django.contrib.auth.backends.ModelBackend",
Expand Down

0 comments on commit 3397298

Please sign in to comment.