mirror of
https://github.com/healthchecks/healthchecks.git
synced 2025-04-08 14:40:05 +00:00
Update Flip.select_channels() to sort channels by last_notify_duration
If a check has multiple associated channels, some are slow and some are quick, handle the quick ones first.
This commit is contained in:
parent
f60af9a156
commit
f241d070e1
2 changed files with 16 additions and 0 deletions
hc/api
|
@ -1173,6 +1173,7 @@ class Flip(models.Model):
|
|||
* Exclude all channels for new->up and paused->up transitions.
|
||||
* Exclude disabled channels
|
||||
* Exclude channels where transport.is_noop(status) returns True
|
||||
* Sort channels by last_notify_duration (shorter durations first)
|
||||
"""
|
||||
|
||||
# Don't send alerts on new->up and paused->up transitions
|
||||
|
@ -1183,6 +1184,7 @@ class Flip(models.Model):
|
|||
raise NotImplementedError(f"Unexpected status: {self.new_status}")
|
||||
|
||||
q = self.owner.channel_set.exclude(disabled=True)
|
||||
q = q.order_by("last_notify_duration")
|
||||
return [ch for ch in q if not ch.transport.is_noop(self.new_status)]
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from datetime import timedelta as td
|
||||
|
||||
from django.utils.timezone import now
|
||||
|
||||
|
@ -51,3 +52,16 @@ class FlipModelTestCase(BaseTestCase):
|
|||
|
||||
channels = self.flip.select_channels()
|
||||
self.assertEqual(channels, [])
|
||||
|
||||
def test_it_sorts_channels_by_last_notify_duration(self) -> None:
|
||||
c1 = Channel.objects.create(
|
||||
project=self.project, kind="email", last_notify_duration=td(seconds=1)
|
||||
)
|
||||
c1.checks.add(self.check)
|
||||
c9 = Channel.objects.create(
|
||||
project=self.project, kind="email", last_notify_duration=td(seconds=9)
|
||||
)
|
||||
c9.checks.add(self.check)
|
||||
|
||||
channels = self.flip.select_channels()
|
||||
self.assertEqual(channels, [c1, c9, self.channel])
|
||||
|
|
Loading…
Add table
Reference in a new issue