feat: add scheduler and mail outbox
SMTP adapter with TLS and a fake, outbox with retries, backoff, rate limit and restart safety, scheduler tick with job-run records started by gunicorn, and a send_test_mail command. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01N3t4WL7bd9bdHHNjEsxzqC
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
from django.db import models
|
||||
|
||||
|
||||
class OutboxMail(models.Model):
|
||||
"""One e-mail waiting to be sent, being sent, sent or failed. Owned by `mailer` (AD-19)."""
|
||||
|
||||
class Status(models.TextChoices):
|
||||
QUEUED = "queued"
|
||||
SENDING = "sending"
|
||||
SENT = "sent"
|
||||
FAILED = "failed"
|
||||
|
||||
template = models.CharField(max_length=100)
|
||||
recipient = models.CharField(max_length=254)
|
||||
subject = models.CharField(max_length=300)
|
||||
# Kept only until the mail is sent: it may hold a one-time link.
|
||||
body_text = models.TextField(blank=True)
|
||||
status = models.CharField(max_length=10, choices=Status.choices, default=Status.QUEUED)
|
||||
attempts = models.PositiveSmallIntegerField(default=0)
|
||||
created_at = models.DateTimeField()
|
||||
next_attempt_at = models.DateTimeField()
|
||||
claimed_at = models.DateTimeField(null=True, blank=True)
|
||||
sent_at = models.DateTimeField(null=True, blank=True)
|
||||
# What went wrong, in words without the recipient or the text of the mail.
|
||||
last_error = models.CharField(max_length=200, blank=True)
|
||||
|
||||
class Meta:
|
||||
indexes = [models.Index(fields=["status", "next_attempt_at"])]
|
||||
ordering = ["id"]
|
||||
Reference in New Issue
Block a user