Remove unnecessary signal (#2030)
# What this PR does ## Which issue(s) this PR fixes ## Checklist - [ ] Unit, integration, and e2e (if applicable) tests updated - [ ] Documentation added (or `pr:no public docs` PR label added if not required) - [ ] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not required)
This commit is contained in:
parent
926ba3956c
commit
9a6618bbc3
3 changed files with 15 additions and 36 deletions
|
|
@ -1,4 +1,4 @@
|
|||
from .alert import Alert, listen_for_alert_model_save # noqa: F401
|
||||
from .alert import Alert # noqa: F401
|
||||
from .alert_group import AlertGroup # noqa: F401
|
||||
from .alert_group_counter import AlertGroupCounter # noqa: F401
|
||||
from .alert_group_log_record import AlertGroupLogRecord, listen_for_alertgrouplogrecord # noqa: F401
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ from django.conf import settings
|
|||
from django.core.validators import MinLengthValidator
|
||||
from django.db import models
|
||||
from django.db.models import JSONField
|
||||
from django.db.models.signals import post_save
|
||||
|
||||
from apps.alerts.constants import TASK_DELAY_SECONDS
|
||||
from apps.alerts.incident_appearance.templaters import TemplateLoader
|
||||
|
|
@ -82,6 +81,10 @@ class Alert(models.Model):
|
|||
channel_filter=None,
|
||||
force_route_id=None,
|
||||
):
|
||||
"""
|
||||
Creates an alert and a group if needed.
|
||||
"""
|
||||
# This import is here to avoid circular imports
|
||||
ChannelFilter = apps.get_model("alerts", "ChannelFilter")
|
||||
AlertGroup = apps.get_model("alerts", "AlertGroup")
|
||||
AlertReceiveChannel = apps.get_model("alerts", "AlertReceiveChannel")
|
||||
|
|
@ -125,6 +128,16 @@ class Alert(models.Model):
|
|||
|
||||
alert.save()
|
||||
|
||||
# Store exact alert which resolved group.
|
||||
if group.resolved_by == AlertGroup.SOURCE and group.resolved_by_alert is None:
|
||||
group.resolved_by_alert = alert
|
||||
group.save(update_fields=["resolved_by_alert"])
|
||||
|
||||
if settings.DEBUG:
|
||||
distribute_alert(alert.pk)
|
||||
else:
|
||||
distribute_alert.apply_async((alert.pk,), countdown=TASK_DELAY_SECONDS)
|
||||
|
||||
if group_created:
|
||||
# all code below related to maintenance mode
|
||||
maintenance_uuid = None
|
||||
|
|
@ -255,32 +268,3 @@ class Alert(models.Model):
|
|||
distinction = str(uuid4())
|
||||
|
||||
return distinction
|
||||
|
||||
|
||||
def listen_for_alert_model_save(sender, instance, created, *args, **kwargs):
|
||||
AlertGroup = apps.get_model("alerts", "AlertGroup")
|
||||
"""
|
||||
Here we invoke AlertShootingStep by model saving action.
|
||||
"""
|
||||
if created:
|
||||
# RFCT - why additinal save ?
|
||||
instance.save()
|
||||
|
||||
group = instance.group
|
||||
# Store exact alert which resolved group.
|
||||
if group.resolved_by == AlertGroup.SOURCE and group.resolved_by_alert is None:
|
||||
group.resolved_by_alert = instance
|
||||
group.save(update_fields=["resolved_by_alert"])
|
||||
|
||||
if settings.DEBUG:
|
||||
distribute_alert(instance.pk)
|
||||
else:
|
||||
distribute_alert.apply_async((instance.pk,), countdown=TASK_DELAY_SECONDS)
|
||||
|
||||
|
||||
# Connect signal to base Alert class
|
||||
post_save.connect(listen_for_alert_model_save, Alert)
|
||||
|
||||
# And subscribe for events from child classes
|
||||
for subclass in Alert.__subclasses__():
|
||||
post_save.connect(listen_for_alert_model_save, subclass)
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ from apps.alerts.models import (
|
|||
AlertReceiveChannel,
|
||||
MaintainableObject,
|
||||
ResolutionNote,
|
||||
listen_for_alert_model_save,
|
||||
listen_for_alertgrouplogrecord,
|
||||
listen_for_alertreceivechannel_model_save,
|
||||
)
|
||||
|
|
@ -610,9 +609,7 @@ def make_resolution_note_slack_message():
|
|||
@pytest.fixture
|
||||
def make_alert():
|
||||
def _make_alert(alert_group, raw_request_data, **kwargs):
|
||||
post_save.disconnect(listen_for_alert_model_save, sender=Alert)
|
||||
alert = AlertFactory(group=alert_group, raw_request_data=raw_request_data, **kwargs)
|
||||
post_save.connect(listen_for_alert_model_save, sender=Alert)
|
||||
return alert
|
||||
|
||||
return _make_alert
|
||||
|
|
@ -630,7 +627,6 @@ def make_alert_with_custom_create_method():
|
|||
raw_request_data,
|
||||
**kwargs,
|
||||
):
|
||||
post_save.disconnect(listen_for_alert_model_save, sender=Alert)
|
||||
alert = Alert.create(
|
||||
title,
|
||||
message,
|
||||
|
|
@ -641,7 +637,6 @@ def make_alert_with_custom_create_method():
|
|||
raw_request_data,
|
||||
**kwargs,
|
||||
)
|
||||
post_save.connect(listen_for_alert_model_save, sender=Alert)
|
||||
return alert
|
||||
|
||||
return _make_alert_with_custom_create_method
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue