Skip to content

Commit

Permalink
Merge pull request #11 from andela/ft-running-too-often-156687758
Browse files Browse the repository at this point in the history
Ft running too often 156687758
  • Loading branch information
Joan Ngatia committed May 7, 2018
2 parents 0e8e87d + e00e7ec commit 396a76d
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion hc/api/migrations/0027_auto_20180503_1855.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name='check',
name='status',
field=models.CharField(choices=[('up', 'Up'), ('down', 'Down'), ('new', 'New'), ('paused', 'Paused'), ('often', 'Too often')], default='new', max_length=6),
field=models.CharField(choices=[('up', 'Up'), ('down', 'Down'), ('new', 'New'), ('paused', 'Paused'), ('too often', 'Too often')], default='new', max_length=9),
),
]
8 changes: 4 additions & 4 deletions hc/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
("down", "Down"),
("new", "New"),
("paused", "Paused"),
("often", "Too often")
("too often", "Too often")
)
DEFAULT_TIMEOUT = td(days=1)
DEFAULT_GRACE = td(hours=1)
Expand Down Expand Up @@ -53,7 +53,7 @@ class Meta:
last_ping = models.DateTimeField(null=True, blank=True)
next_ping = models.DateTimeField(null=True, blank=True)
alert_after = models.DateTimeField(null=True, blank=True, editable=False)
status = models.CharField(max_length=6, choices=STATUSES, default="new")
status = models.CharField(max_length=9, choices=STATUSES, default="new")

def name_then_code(self):
if self.name:
Expand All @@ -71,7 +71,7 @@ def email(self):
return "%s@%s" % (self.code, settings.PING_EMAIL_DOMAIN)

def send_alert(self):
if self.status not in ("up", "down", "often"):
if self.status not in ("up", "down", "too often"):
raise NotImplementedError("Unexpected status: %s" % self.status)

errors = []
Expand All @@ -87,7 +87,7 @@ def get_status(self):
return self.status

now = timezone.now()
if self.status == 'often':
if self.status == 'too often':
if now > self.next_ping:
return "down"
return self.status
Expand Down
14 changes: 10 additions & 4 deletions hc/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,21 @@ def ping(request, code):
except Check.DoesNotExist:
return HttpResponseBadRequest()

if check.running_too_often():
check.status = "often"
if check.status in ("new", "paused"):
check.status = "up"

# only confirm if a check is too_often if the check is not in down-wise statuses
if check.status not in ("down"):
if check.running_too_often():
check.status = "too often"
else:
check.status = "up"

now = timezone.now()
check.n_pings = F("n_pings") + 1
check.last_ping = now
# store expected time for next ping
check.next_ping = now + check.timeout
if check.status in ("new", "paused"):
check.status = "up"

check.save()
check.refresh_from_db()
Expand Down
2 changes: 1 addition & 1 deletion templates/front/my_checks_desktop.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
{% if check.get_status == "new" %}
<span class="status icon-up new"
data-toggle="tooltip" title="New. Has never received a ping."></span>
{% elif check.get_status == "often" %}
{% elif check.get_status == "too often" %}
<span class="status icon-often"
data-toggle="tooltip" title="Too often. Ran too early."></span>
{% elif check.get_status == "paused" %}
Expand Down
2 changes: 1 addition & 1 deletion templates/front/my_checks_mobile.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ <h2>
<span class="label label-warning">LATE</span>
{% elif check.get_status == "up" %}
<span class="label label-success">UP</span>
{% elif check.get_status == "often" %}
{% elif check.get_status == "too often" %}
<span class="label label-warning">EARLY</span>
{% elif check.get_status == "down" %}
<span class="label label-danger">DOWN</span>
Expand Down

0 comments on commit 396a76d

Please sign in to comment.