forked from GithubBackups/healthchecks
In the "List checks" API response, the "next_ping" date was incorrect for checks using cron syntax. Fixed.
This commit is contained in:
parent
b6f6ca2f2b
commit
a62350cdad
@ -1,6 +1,5 @@
|
|||||||
import json
|
import json
|
||||||
import re
|
import re
|
||||||
import uuid
|
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
|
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
|
@ -47,6 +47,11 @@ PO_PRIORITIES = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def isostring(dt):
|
||||||
|
"""Convert the datetime to ISO 8601 format with no microseconds. """
|
||||||
|
return dt.replace(microsecond=0).isoformat()
|
||||||
|
|
||||||
|
|
||||||
class Check(models.Model):
|
class Check(models.Model):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
@ -167,8 +172,8 @@ class Check(models.Model):
|
|||||||
result["tz"] = self.tz
|
result["tz"] = self.tz
|
||||||
|
|
||||||
if self.last_ping:
|
if self.last_ping:
|
||||||
result["last_ping"] = self.last_ping.replace(microsecond=0).isoformat()
|
result["last_ping"] = isostring(self.last_ping)
|
||||||
result["next_ping"] = (self.last_ping + self.timeout).replace(microsecond=0).isoformat()
|
result["next_ping"] = isostring(self.get_grace_start())
|
||||||
else:
|
else:
|
||||||
result["last_ping"] = None
|
result["last_ping"] = None
|
||||||
result["next_ping"] = None
|
result["next_ping"] = None
|
||||||
|
@ -74,3 +74,16 @@ class CheckModelTestCase(TestCase):
|
|||||||
# 11:30am
|
# 11:30am
|
||||||
now = dt + timedelta(days=1, minutes=90)
|
now = dt + timedelta(days=1, minutes=90)
|
||||||
self.assertEqual(check.get_status(now), "down")
|
self.assertEqual(check.get_status(now), "down")
|
||||||
|
|
||||||
|
def test_next_ping_with_cron_syntax(self):
|
||||||
|
dt = timezone.make_aware(datetime(2000, 1, 1), timezone=timezone.utc)
|
||||||
|
|
||||||
|
# Expect ping every round hour
|
||||||
|
check = Check()
|
||||||
|
check.kind = "cron"
|
||||||
|
check.schedule = "0 * * * *"
|
||||||
|
check.status = "up"
|
||||||
|
check.last_ping = dt
|
||||||
|
|
||||||
|
d = check.to_dict()
|
||||||
|
self.assertEqual(d["next_ping"], "2000-01-01T01:00:00+00:00")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user