Browse Source

Check.in_grace_period() looks at `last_ping_was_fail` flag.

pull/178/head
Pēteris Caune 7 years ago
parent
commit
dfcf7aafbe
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
2 changed files with 13 additions and 0 deletions
  1. +3
    -0
      hc/api/models.py
  2. +10
    -0
      hc/api/tests/test_check_model.py

+ 3
- 0
hc/api/models.py View File

@ -146,6 +146,9 @@ class Check(models.Model):
if self.status in ("new", "paused"):
return False
if self.last_ping_was_fail:
return False
grace_start = self.get_grace_start()
grace_end = grace_start + self.grace
return grace_start < timezone.now() < grace_end


+ 10
- 0
hc/api/tests/test_check_model.py View File

@ -20,6 +20,16 @@ class CheckModelTestCase(TestCase):
check = Check()
self.assertFalse(check.in_grace_period())
def test_in_grace_period_handles_fail_ping(self):
check = Check()
check.status = "up"
check.last_ping = timezone.now() - timedelta(days=1, minutes=30)
check.last_ping_was_fail = True
# If last ping was signalling a failure, we're not in grace period,
# we're down
self.assertFalse(check.in_grace_period())
def test_status_works_with_grace_period(self):
check = Check()
check.status = "up"


Loading…
Cancel
Save