Skip to content

Commit 81a042a

Browse files
committed
wrap disable in transaction
1 parent 98c39b9 commit 81a042a

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/sentry/uptime/subscriptions/tasks.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from datetime import timedelta
55
from uuid import uuid4
66

7+
from django.db import router
78
from django.utils import timezone
89

910
from sentry.tasks.base import instrumented_task
@@ -12,6 +13,7 @@
1213
from sentry.taskworker.retry import Retry
1314
from sentry.uptime.config_producer import produce_config, produce_config_removal
1415
from sentry.uptime.models import (
16+
ProjectUptimeSubscription,
1517
UptimeRegionScheduleMode,
1618
UptimeStatus,
1719
UptimeSubscription,
@@ -20,7 +22,9 @@
2022
)
2123
from sentry.uptime.types import CheckConfig, ProjectUptimeSubscriptionMode
2224
from sentry.utils import metrics
25+
from sentry.utils.db import atomic_transaction
2326
from sentry.utils.query import RangeQuerySetWrapper
27+
from sentry.workflow_engine.models.detector import Detector
2428

2529
logger = logging.getLogger(__name__)
2630

@@ -232,7 +236,14 @@ def broken_monitor_checker(**kwargs):
232236
detector = get_detector(uptime_subscription)
233237
assert detector
234238
if detector.config["mode"] == ProjectUptimeSubscriptionMode.AUTO_DETECTED_ACTIVE:
235-
disable_uptime_detector(detector)
236-
count += 1
239+
with atomic_transaction(
240+
using=(
241+
router.db_for_write(UptimeSubscription),
242+
router.db_for_write(ProjectUptimeSubscription),
243+
router.db_for_write(Detector),
244+
)
245+
):
246+
disable_uptime_detector(detector)
247+
count += 1
237248

238249
metrics.incr("uptime.subscriptions.disable_broken", amount=count, sample_rate=1.0)

0 commit comments

Comments
 (0)