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
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,
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),
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()
{%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>
{%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%}
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%}
{%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#}
<span class="label label-danger">No entries found</span>
{%endif%}
{%endif%}
+ </div>
</td>
<td>
{%if not blog.archived%}