Make use of the lastsuccess parameter to improve some messages
authorMagnus Hagander <magnus@hagander.net>
Sat, 11 Jul 2020 17:22:12 +0000 (19:22 +0200)
committerMagnus Hagander <magnus@hagander.net>
Sat, 11 Jul 2020 17:22:12 +0000 (19:22 +0200)
In particular, it is interesting to know when a blog that has failed
multiple times has actually succeeded more recent than the most recent
failure. So show this both on the dashbaord and on the individual blog
details, and include it in the email that's sent when a blog generates
large amounts of errors.

hamnadmin/hamnadmin/register/management/commands/send_logs.py
hamnadmin/hamnadmin/register/models.py
hamnadmin/hamnadmin/register/templates/edit.html
hamnadmin/hamnadmin/register/templates/index.html
www/css/planet_reg.css

index 5e7dc326f75103819f7ac1542b620d5bd9402010..c8451c406d72e4e36d4c8d6c2d0ccc5638186247 100644 (file)
@@ -1,6 +1,6 @@
 from django.core.management.base import BaseCommand
 from django.db import transaction
-from django.db.models import Count
+from django.db.models import Count, Max
 from django.conf import settings
 
 from datetime import datetime, timedelta
@@ -22,8 +22,14 @@ class Command(BaseCommand):
                     aggregatorlog__success=False,
                     aggregatorlog__ts__gt=datetime.now() - timedelta(days=1),
             ).annotate(
-                num=Count("aggregatorlog__id")
+                num=Count("aggregatorlog__id"),
+                last=Max("aggregatorlog__ts"),
             ).filter(num__gt=THRESHOLD).order_by():
+                if feed.lastsuccess and feed.lastsuccess > feed.last:
+                    success_str = "\nNote that there has been a successful fetch at\n{}, which is more recent than any errors.\n".format(feed.lastsuccess)
+                else:
+                    success_str = ""
+
                 # We assume this is only run once a day, so just generate one email
                 send_simple_mail(
                     settings.EMAIL_SENDER,
@@ -41,20 +47,21 @@ https://planet.postgresql.org/register/edit/{2}/
 using your normal PostgreSQL community login. From this page you
 will be able to see what the errors were, so that you can correct
 them.
-
+{3}
 If this is a blog that is no longer active, please go to the same
 page linked above, and click the button to Archive the blog. That
 will prevent Planet PostgreSQL from trying to fetch new entries,
 and also stop these messages from being sent.
 
 A message like this will be sent once a day as long as your blog
-is generating more than {3} errors per day.
+is generating more than {4} errors per day.
 
 """.
                     format(
                         feed.feedurl,
                         feed.num,
                         feed.id,
+                        success_str,
                         THRESHOLD),
                     sendername="Planet PostgreSQL",
                     receivername="{0} {1}".format(feed.user.first_name, feed.user.last_name),
index 04e8edac1ba30a6307bf927c326bc00da9de6585..6377a8a06a98963f2cecd3f5fb53db18eb111268 100644 (file)
@@ -53,6 +53,12 @@ class Blog(models.Model):
     def recent_failures(self):
         return self.aggregatorlog_set.filter(success=False, ts__gt=datetime.now() - timedelta(days=1)).count()
 
+    def last_was_error(self):
+        if self.lastsuccess:
+            return self.aggregatorlog_set.filter(success=False, ts__gt=self.lastsuccess).exists()
+        else:
+            return self.aggregatorlog_set.filter(success=False).exists()
+
     @property
     def has_entries(self):
         return self.posts.filter(hidden=False).exists()
index 0d53d8e07fcf89576c0748726fb80ac0da764130..d0ef00047cc89d450c34d9218fc739f0699bc8cd 100644 (file)
@@ -106,6 +106,11 @@ The blog is currently waiting for moderator approval.
 {%if not new%}
 <a name="log"></a>
 <h3>Log</h3>
+{%if blog.lastsuccess%}
+<p>
+  The last successful fetch of this feed was <em>{{blog.lastsuccess|date:"Y-m-d H:i:s"}}.</em>
+</p>
+{%endif%}
 <table class="table table-condensed table-striped">
   <tr>
     <th>Time</th>
@@ -115,7 +120,11 @@ The blog is currently waiting for moderator approval.
   {%for l in log%}
   <tr>
     <td>{{l.ts|date:"Y-m-d H:i:s"}}</td>
-    <td><span class="label label-{{l.success|yesno:"success,danger"}}">{{l.success|yesno:"Success,Failure"}}</span></td>
+    <td>
+{%if l.success%}<span class="label label-success">Success</span>
+{%elif l.ts < blog.lastsuccess%}<span class="label label-warning" title="A successful fetch has been completed after this failure occurred">Past failure</span>
+{%else%}<span class="label label-danger">Failure</span>{%endif%}
+    </td>
     <td>{{l.info}}</td>
   </tr>
   {%endfor%}
index e6e1c876803b2b001f47a251b412f42ba59dd53f..b9c0d778393bf593b92f7e44cb71d91b10fae3d3 100644 (file)
@@ -36,7 +36,8 @@ You have the following blog(s) registered:
 Last http get: {{blog.lastget|date:"Y-m-d H:i:s"}}<br/>
  </td>
 
- <td>
+ <td class="feedstatus">
+   <div>
    {%if blog.archived%}
    <span class="label label-info">Archived</span>
    {%elif blog.approved%}
@@ -46,6 +47,10 @@ Last http get: {{blog.lastget|date:"Y-m-d H:i:s"}}<br/>
      {%else%}
       <a href="edit/{{blog.id}}/#log"><span class="label label-warning">Sporadic errors</span></a>
     {%endif%}
+      </div>
+      <div>
+      {% if blog.last_was_error%}<span class="label label-danger">Last attempt failed</span>
+      {%else%}<span class="label label-success">Last attempt succeeded</span>{%endif%}
    {%else%}
     <span class="label label-success">Approved and working</span>
    {%endif%}{#recent_failures#}
@@ -56,6 +61,7 @@ Last http get: {{blog.lastget|date:"Y-m-d H:i:s"}}<br/>
     <span class="label label-danger">No entries found</span>
    {%endif%}
   {%endif%}
+   </div>
  </td>
  <td>
    {%if not blog.archived%}
index 39de46339a3143277261d87c69b64d191b337976..4680a4e4cf7be60d13de45f51ccced3beb01ee8a 100644 (file)
@@ -7,3 +7,7 @@ div#planethdr {
 input.form-control[type=checkbox] {
 width: 10px;
 }
+
+td.feedstatus div {
+    margin-bottom: 0.5rem;
+}