Complete the sendtime handling for mailqueue
authorMagnus Hagander <magnus@hagander.net>
Tue, 14 May 2024 11:46:20 +0000 (13:46 +0200)
committerMagnus Hagander <magnus@hagander.net>
Tue, 14 May 2024 11:46:20 +0000 (13:46 +0200)
Sync up the "warning button" filtering with that of the alerts, which
means we donÍ„'t alert for emails that aren't supposed to be sent yet.
This becomes more relevant as we also stop trying to send emails that
are set to be sent in the future, in preparation for upcoming
functionality to schedule email sending.

postgresqleu/mailqueue/backendforms.py
postgresqleu/mailqueue/management/commands/send_queued_mail.py
postgresqleu/views.py

index 7ccfbdd9d5c4d2839915f65ef6dd4e270d97468f..bb79752a15076f9cb77ed310e48f87a06697014e 100644 (file)
@@ -1,4 +1,5 @@
 from django import forms
+from django.utils import timezone
 
 from collections import OrderedDict
 
@@ -40,3 +41,10 @@ class BackendMailqueueForm(BackendForm):
             self.instance.parsed_msg, self.instance.parsed_txt = parse_mail_content(self.instance.fullmsg)
 
         return self.instance.parsed_txt
+
+    @classmethod
+    def get_rowclass_and_title(self, obj, cache):
+        if obj.sendtime < timezone.now():
+            return "warning", None
+        else:
+            return "", None
index e4fa78aecc4d12951c9c9814b657ec12ee2d8ece..d3e368481665bdd07cbe81b3b634cfd597e067e9 100755 (executable)
@@ -8,6 +8,7 @@
 from django.core.management.base import BaseCommand, CommandError
 from django.db import connection
 from django.conf import settings
+from django.utils import timezone
 
 import smtplib
 
@@ -26,7 +27,7 @@ class Command(BaseCommand):
         if not curs.fetchall()[0][0]:
             raise CommandError("Failed to get advisory lock, existing send_queued_mail process stuck?")
 
-        for m in QueuedMail.objects.all():
+        for m in QueuedMail.objects.filter(sendtime__lte=timezone.now()):
             # Yes, we do a new connection for each run. Just because we can.
             # If it fails we'll throw an exception and just come back on the
             # next cron job. And local delivery should never fail...
index 63484b702b68959c9a9c8467ce1f9636844fda9e..68bc9360980d54ed9abb9a3c96bab73925341cf4 100644 (file)
@@ -176,7 +176,7 @@ def admin_dashboard(request):
         'pending_refunds': pending_refunds,
         'bank_file_uploads': bank_file_uploads,
         'schedalert': conditional_exec_to_scalar(request.user.is_superuser, "SELECT NOT EXISTS (SELECT 1 FROM pg_stat_activity WHERE application_name='pgeu scheduled job runner' AND datname=current_database())"),
-        'mailqueuealert': conditional_exec_to_scalar(request.user.is_superuser, "SELECT EXISTS (SELECT 1 FROM mailqueue_queuedmail LIMIT 1)"),
+        'mailqueuealert': conditional_exec_to_scalar(request.user.is_superuser, "SELECT EXISTS (SELECT 1 FROM mailqueue_queuedmail WHERE sendtime < now())"),
         'meetingserver': settings.ENABLE_MEMBERSHIP and settings.MEETINGS_STATUS_BASE_URL,
     })