Просмотр исходного кода

ref(crons): Move SimpleCheckIn back to just incident module (#80774)

Turns out we actually really don't need to expose this type more
broadly, and can just use it only in this module.
Evan Purkhiser 3 месяцев назад
Родитель
Сommit
b2ce8614c0
3 измененных файлов с 19 добавлено и 18 удалено
  1. 18 3
      src/sentry/monitors/logic/incidents.py
  2. 1 4
      src/sentry/monitors/models.py
  3. 0 11
      src/sentry/monitors/types.py

+ 18 - 3
src/sentry/monitors/logic/incidents.py

@@ -1,6 +1,7 @@
 from __future__ import annotations
 
 import logging
+from dataclasses import dataclass
 from datetime import datetime, timedelta
 
 from django.utils import timezone
@@ -12,11 +13,25 @@ from sentry.monitors.logic.incident_occurrence import (
 )
 from sentry.monitors.models import CheckInStatus, MonitorCheckIn, MonitorIncident, MonitorStatus
 from sentry.monitors.tasks.detect_broken_monitor_envs import NUM_DAYS_BROKEN_PERIOD
-from sentry.monitors.types import SimpleCheckIn
 
 logger = logging.getLogger(__name__)
 
 
+@dataclass
+class SimpleCheckIn:
+    """
+    A stripped down check in object
+    """
+
+    id: int
+    date_added: datetime
+    status: int
+
+    @classmethod
+    def from_checkin(cls, checkin: MonitorCheckIn) -> SimpleCheckIn:
+        return cls(checkin.id, checkin.date_added, checkin.status)
+
+
 def try_incident_threshold(
     failed_checkin: MonitorCheckIn,
     received: datetime | None,
@@ -45,7 +60,7 @@ def try_incident_threshold(
     # check to see if we need to update the status
     if monitor_env.status in [MonitorStatus.OK, MonitorStatus.ACTIVE]:
         if failure_issue_threshold == 1:
-            previous_checkins: list[SimpleCheckIn] = [failed_checkin.as_simple_checkin()]
+            previous_checkins: list[SimpleCheckIn] = [SimpleCheckIn.from_checkin(failed_checkin)]
         else:
             previous_checkins = [
                 SimpleCheckIn(**row)
@@ -86,7 +101,7 @@ def try_incident_threshold(
     elif monitor_env.status == MonitorStatus.ERROR:
         # if monitor environment has a failed status, use the failed
         # check-in and send occurrence
-        previous_checkins = [failed_checkin.as_simple_checkin()]
+        previous_checkins = [SimpleCheckIn.from_checkin(failed_checkin)]
 
         # get the active incident from the monitor environment
         incident = monitor_env.active_incident

+ 1 - 4
src/sentry/monitors/models.py

@@ -37,7 +37,7 @@ from sentry.db.models.utils import slugify_instance
 from sentry.locks import locks
 from sentry.models.environment import Environment
 from sentry.models.rule import Rule, RuleSource
-from sentry.monitors.types import CrontabSchedule, IntervalSchedule, SimpleCheckIn
+from sentry.monitors.types import CrontabSchedule, IntervalSchedule
 from sentry.types.actor import Actor
 from sentry.utils.retries import TimedRetryPolicy
 
@@ -581,9 +581,6 @@ class MonitorCheckIn(Model):
     def _update_timestamps(self):
         pass
 
-    def as_simple_checkin(self) -> SimpleCheckIn:
-        return SimpleCheckIn(self.id, self.date_added, self.status)
-
 
 def delete_file_for_monitorcheckin(instance: MonitorCheckIn, **kwargs):
     if file_id := instance.attachment_id:

+ 0 - 11
src/sentry/monitors/types.py

@@ -101,17 +101,6 @@ class CheckinItem:
         )
 
 
-@dataclass
-class SimpleCheckIn:
-    """
-    A stripped down check in object
-    """
-
-    id: int
-    date_added: datetime
-    status: int
-
-
 IntervalUnit = Literal["year", "month", "week", "day", "hour", "minute"]