Skip to content

Commit

Permalink
feat(statuses): Add often status with icon-often
Browse files Browse the repository at this point in the history
	- Added a class for icon-often with a title
	-Feature notifys a user that a job has been ran too often through email and an icon in the UI

feat(labels): Add often status as a label

feat(icons): Add an icon to show that a job runs too often

bg(comments):Delete commented out code

ch(line spacing):Fix line to follow pep8
	-Feature notifys a user that a job has been ran too often through email and an icon in the UI

feat(attributes):Replace atrribute status with often

	- Replaced set attributes for status as often to a boolean value that was set as true

feat(attributes): Add attribute often

	-Added an attribute called often and set it to a boolean

feat(exceptions):Add try method to set often(attribute) as true

	-Added a try method that set attribute often as true and saves it.

bg(merge errors):Fix merge errors

ch(requirements):Update requirements file

ch(migrations):Add migrations
  • Loading branch information
Ace authored and Ace committed Sep 14, 2017
1 parent 8caf183 commit dd684a1
Show file tree
Hide file tree
Showing 11 changed files with 250 additions and 207 deletions.
8 changes: 5 additions & 3 deletions hc/api/management/commands/sendalerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


class Command(BaseCommand):
help = 'Sends UP/DOWN email alerts'
help = 'Sends UP/DOWN/OFTEN email alerts'

def handle_many(self):
""" Send alerts for many checks simultaneously. """
Expand All @@ -21,9 +21,10 @@ def handle_many(self):
now = timezone.now()
going_down = query.filter(alert_after__lt=now, status="up")
going_up = query.filter(alert_after__gt=now, status="down")
early_ping = query.filter(status="often")
early_ping = query.filter(often=True)
# Don't combine this in one query so Postgres can query using index:
checks = list(going_down.iterator()) + list(going_up.iterator()) + list(early_ping.iterator())
checks = list(going_down.iterator()) + list(going_up.iterator()) \
+ list(early_ping.iterator())
if not checks:
return False

Expand All @@ -44,6 +45,7 @@ def handle_one(self, check):
# Save the new status. If sendalerts crashes,
# it won't process this check again.
check.status = check.get_status()
check.often = False
check.save()

tmpl = "\nSending alert, status=%s, code=%s\n"
Expand Down
25 changes: 25 additions & 0 deletions hc/api/migrations/0027_auto_20170914_0715.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10 on 2017-09-14 07:15
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('api', '0026_auto_20160415_1824'),
]

operations = [
migrations.AddField(
model_name='check',
name='often',
field=models.BooleanField(default=False),
),
migrations.AlterField(
model_name='check',
name='status',
field=models.CharField(choices=[('up', 'Up'), ('down', 'Down'), ('new', 'New'), ('paused', 'Paused'), ('often', 'Often')], default='new', max_length=6),
),
]
9 changes: 5 additions & 4 deletions hc/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ class Meta:
created = models.DateTimeField(auto_now_add=True)
timeout = models.DurationField(default=DEFAULT_TIMEOUT)
grace = models.DurationField(default=DEFAULT_GRACE)
# reverse_grace = models.DurationField(default=REVERSE_GRACE)
n_pings = models.IntegerField(default=0)
last_ping = models.DateTimeField(null=True, blank=True)
alert_after = models.DateTimeField(null=True, blank=True, editable=False)
often = models.BooleanField(default=False)
status = models.CharField(max_length=6, choices=STATUSES, default="new")

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

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

errors = []
Expand All @@ -89,7 +89,8 @@ def get_status(self):

now = timezone.now()

# use the 'ping_set' dictionary to get the last 2 pings
### Use the 'ping_set' dictionary to get the last 2 pings
# The dict should have 2 or more items
if len(self.ping_set.all()) > 2:
# Set the reversed grace period to whatever fraction of 'timeout' you want it to be
reversed_grace_period = self.timeout/5
Expand All @@ -100,7 +101,7 @@ def get_status(self):

if self.last_ping + self.timeout + self.grace > now:
# Set condition to check if ping runs before the set 'timeout'
if (self.last_ping - second_last_ping) - reversed_grace_period < self.timeout:
if (self.last_ping - second_last_ping) < self.timeout - reversed_grace_period:
return "often"
else:
return "up"
Expand Down
7 changes: 6 additions & 1 deletion hc/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ def ping(request, code):
check = Check.objects.get(code=code)
except Check.DoesNotExist:
return HttpResponseBadRequest()

try:
if timezone.now() < (check.last_ping + check.timeout):
check.often = True
check.save()
except:
pass
check.n_pings = F("n_pings") + 1
check.last_ping = timezone.now()
if check.status in ("new", "paused", "often"):
Expand Down
5 changes: 2 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ django-compressor==2.1
django-ses-backend==0.1.1
djmail==0.11.0
futures==3.0.3
gunicorn==19.7.1
isort==4.2.15
lazy-object-proxy==1.3.1
gunicorn==19.7.1
lxml==3.8.0
mccabe==0.6.1
mock==2.0.0
Expand All @@ -28,6 +28,5 @@ rjsmin==1.0.12
sendgrid==3.6.5
sendgrid-django==4.0.4
six==1.10.0
wrapt==1.10.11
whitenoise==3.3.0

wrapt==1.10.11
2 changes: 1 addition & 1 deletion static/fonts/icomoon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit dd684a1

Please sign in to comment.