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"
|
fake_code = "07c2f548-9850-4b27-af5d-6c9dc157ec02"
|
||||||
url = f"/api/v1/notifications/{fake_code}/status"
|
url = f"/api/v1/notifications/{fake_code}/status"
|
||||||
r = self.client.post(url, {"MessageStatus": "failed"})
|
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):
|
def test_it_requires_post(self):
|
||||||
r = self.client.get(self.url)
|
r = self.client.get(self.url)
|
||||||
|
@ -436,12 +436,12 @@ def badge(request, badge_key, signature, tag, fmt):
|
|||||||
def notification_status(request, code):
|
def notification_status(request, code):
|
||||||
""" Handle notification delivery status callbacks. """
|
""" Handle notification delivery status callbacks. """
|
||||||
|
|
||||||
notification = get_object_or_404(Notification, code=code)
|
try:
|
||||||
|
cutoff = timezone.now() - td(hours=1)
|
||||||
td = timezone.now() - notification.created
|
notification = Notification.objects.get(code=code, created__gt=cutoff)
|
||||||
if td.total_seconds() > 3600:
|
except Notification.DoesNotExist:
|
||||||
# If the webhook is called more than 1 hour after the notification, ignore it.
|
# 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 HTTP 200 so the other party doesn't retry over and over again:
|
||||||
return HttpResponse()
|
return HttpResponse()
|
||||||
|
|
||||||
error, mark_not_verified = None, False
|
error, mark_not_verified = None, False
|
||||||
|
@ -477,7 +477,6 @@ def cron_preview(request):
|
|||||||
for i in range(0, 6):
|
for i in range(0, 6):
|
||||||
ctx["dates"].append(it.get_next(datetime))
|
ctx["dates"].append(it.get_next(datetime))
|
||||||
|
|
||||||
pass
|
|
||||||
except UnknownTimeZoneError:
|
except UnknownTimeZoneError:
|
||||||
ctx["bad_tz"] = True
|
ctx["bad_tz"] = True
|
||||||
except:
|
except:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user