forked from GithubBackups/healthchecks
Fix hc.api.views.notification_status to always return 200
If the notification does not exist, or is more than a hour old, return HTTP 200 (instead of 400 or 404) so the other party doesn't retry over and over again.
This commit is contained in:
parent
1e84cac37d
commit
44a677f327
@ -67,7 +67,7 @@ class NotificationStatusTestCase(BaseTestCase):
|
||||
fake_code = "07c2f548-9850-4b27-af5d-6c9dc157ec02"
|
||||
url = f"/api/v1/notifications/{fake_code}/status"
|
||||
r = self.client.post(url, {"MessageStatus": "failed"})
|
||||
self.assertEqual(r.status_code, 404)
|
||||
self.assertEqual(r.status_code, 200)
|
||||
|
||||
def test_it_requires_post(self):
|
||||
r = self.client.get(self.url)
|
||||
|
@ -436,12 +436,12 @@ def badge(request, badge_key, signature, tag, fmt):
|
||||
def notification_status(request, code):
|
||||
""" Handle notification delivery status callbacks. """
|
||||
|
||||
notification = get_object_or_404(Notification, code=code)
|
||||
|
||||
td = timezone.now() - notification.created
|
||||
if td.total_seconds() > 3600:
|
||||
# If the webhook is called more than 1 hour after the notification, ignore it.
|
||||
# Return HTTP 200 so the other party doesn't retry over and over again:
|
||||
try:
|
||||
cutoff = timezone.now() - td(hours=1)
|
||||
notification = Notification.objects.get(code=code, created__gt=cutoff)
|
||||
except Notification.DoesNotExist:
|
||||
# If the notification does not exist, or is more than a hour old,
|
||||
# return HTTP 200 so the other party doesn't retry over and over again:
|
||||
return HttpResponse()
|
||||
|
||||
error, mark_not_verified = None, False
|
||||
|
@ -477,7 +477,6 @@ def cron_preview(request):
|
||||
for i in range(0, 6):
|
||||
ctx["dates"].append(it.get_next(datetime))
|
||||
|
||||
pass
|
||||
except UnknownTimeZoneError:
|
||||
ctx["bad_tz"] = True
|
||||
except:
|
||||
|
Loading…
x
Reference in New Issue
Block a user