Skip to content

Commit

Permalink
Change logic to save status for Surge Alerts.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rup-Narayan-Rajbanshi committed Jul 12, 2024
1 parent 5063a01 commit e24350e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
12 changes: 6 additions & 6 deletions notifications/management/commands/update_surge_alert_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
class Command(BaseCommand):
"""
Updating the Surge Alert Status according:
If the alert status is marked as stood_down, then the status is Stood Down.
If the closing timestamp (closes) is earlier than the current date, the status is displayed as Closed.
Otherwise, it is displayed as Open.
If molnix_status is active, status should Open,
If molnix_status is archived, status should be Closed,
If molnix_status is unfilled, status should be Stood Down,
"""

help = "Update surge alert status"
Expand All @@ -29,9 +29,9 @@ def handle(self, *args, **options):
logger.info("Updating Surge alerts status")
SurgeAlert.objects.update(
status=models.Case(
models.When(is_stood_down=True, then=models.Value(SurgeAlertStatus.STOOD_DOWN)),
models.When(closes__lt=now, then=models.Value(SurgeAlertStatus.CLOSED)),
models.When(closes__gte=now, then=models.Value(SurgeAlertStatus.OPEN)),
models.When(molnix_status="active", then=models.Value(SurgeAlertStatus.OPEN)),
models.When(molnix_status="archived", then=models.Value(SurgeAlertStatus.CLOSED)),
models.When(molnix_status="unfilled", then=models.Value(SurgeAlertStatus.STOOD_DOWN)),
default=models.F("status"),
output_field=models.IntegerField(),
)
Expand Down
18 changes: 7 additions & 11 deletions notifications/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,16 @@ class Meta:

def save(self, *args, **kwargs):
"""
If the alert status is marked as stood_down, then the status is Stood Down.
If the closing timestamp (closes) is earlier than the current date, the status is displayed as Closed.
Otherwise, it is displayed as Open.
A molnix_status of active should be shown as Open
A molnix_status of archived should be shown as Closed
A molnix_status of unfilled should be shown as Stood Down
"""
# On save, if `created` is not set, make it the current time
if (not self.id and not self.created_at) or (self.created_at > timezone.now()):
self.created_at = timezone.now()
self.is_stood_down = self.molnix_status == "unfilled"
if self.is_stood_down:
self.status = SurgeAlertStatus.STOOD_DOWN
elif self.closes and self.closes < timezone.now():
if self.molnix_status == 'active':
self.status = SurgeAlertStatus.OPEN
if self.molnix_status == 'archived':
self.status = SurgeAlertStatus.CLOSED
else:
self.status = SurgeAlertStatus.OPEN
self.status = SurgeAlertStatus.STOOD_DOWN
return super(SurgeAlert, self).save(*args, **kwargs)

def __str__(self):
Expand Down

0 comments on commit e24350e

Please sign in to comment.