Browse Source

fix(statistical-detectors): Delay the query period for breakpoint det… (#57382)

…ection

#57230 used the `start` argument to decide the query period. This
ensures that the `start` argument is delayed by the same number of hours
as the task.
Tony Xiao 1 year ago
parent
commit
2d9b7dc1fb
1 changed files with 6 additions and 3 deletions
  1. 6 3
      src/sentry/tasks/statistical_detectors.py

+ 6 - 3
src/sentry/tasks/statistical_detectors.py

@@ -253,16 +253,19 @@ def detect_function_trends(project_ids: List[int], start: datetime, *args, **kwa
     trends = _detect_function_trends(project_ids, start)
     regressions = filter(lambda trend: trend[0] == TrendType.Regressed, trends)
 
+    delay = 12  # hours
+    delayed_start = start + timedelta(hours=delay)
+
     for regression_chunk in chunked(regressions, FUNCTIONS_PER_BATCH):
         detect_function_change_points.apply_async(
             args=[
                 [(payload.project_id, payload.group) for _, payload in regression_chunk],
-                start,
+                delayed_start,
             ],
-            # delay the check by 12 hours because we want to make sure there
+            # delay the check by delay hours because we want to make sure there
             # will be enough data after the potential change point to be confident
             # that a change has occurred
-            countdown=12 * 60 * 60,
+            countdown=delay * 60 * 60,
         )