Browse Source

Move Check.send_alert() to Flip.send_alerts()

pull/211/head
Pēteris Caune 6 years ago
parent
commit
179b085df4
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
2 changed files with 17 additions and 17 deletions
  1. +1
    -1
      hc/api/management/commands/sendalerts.py
  2. +16
    -16
      hc/api/models.py

+ 1
- 1
hc/api/management/commands/sendalerts.py View File

@ -24,7 +24,7 @@ def notify(flip_id, stdout):
check.user.profile.set_next_nag_date()
# Send notifications
errors = check.send_alert(flip)
errors = flip.send_alerts()
for ch, error in errors:
stdout.write("ERROR: %s %s %s\n" % (ch.kind, ch.value, error))


+ 16
- 16
hc/api/models.py View File

@ -100,22 +100,6 @@ class Check(models.Model):
def email(self):
return "%s@%s" % (self.code, settings.PING_EMAIL_DOMAIN)
def send_alert(self, flip):
if flip.new_status == "up" and flip.old_status in ("new", "paused"):
# Don't send alerts on new->up and paused->up transitions
return []
if flip.new_status not in ("up", "down"):
raise NotImplementedError("Unexpected status: %s" % self.status)
errors = []
for channel in self.channel_set.all():
error = channel.notify(self)
if error not in ("", "no-op"):
errors.append((channel, error))
return errors
def get_grace_start(self):
""" Return the datetime when the grace period starts.
@ -588,3 +572,19 @@ class Flip(models.Model):
processed = models.DateTimeField(null=True, blank=True, db_index=True)
old_status = models.CharField(max_length=8, choices=STATUSES)
new_status = models.CharField(max_length=8, choices=STATUSES)
def send_alerts(self):
if self.new_status == "up" and self.old_status in ("new", "paused"):
# Don't send alerts on new->up and paused->up transitions
return []
if self.new_status not in ("up", "down"):
raise NotImplementedError("Unexpected status: %s" % self.status)
errors = []
for channel in self.owner.channel_set.all():
error = channel.notify(self.owner)
if error not in ("", "no-op"):
errors.append((channel, error))
return errors

Loading…
Cancel
Save