OLD | NEW |
---|---|
1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """The datastore model for alerts when data is no longer received for a test.""" | 5 """The datastore model for alerts when data is no longer received for a test.""" |
6 | 6 |
7 import logging | 7 import logging |
8 | 8 |
9 from google.appengine.ext import ndb | 9 from google.appengine.ext import ndb |
10 | 10 |
11 from dashboard import utils | 11 from dashboard import utils |
12 from dashboard.models import alert | 12 from dashboard.models import alert |
13 from dashboard.models import alert_group | 13 from dashboard.models import alert_group |
14 | 14 |
15 _MAX_GROUP_SIZE = 20 | |
16 | |
15 | 17 |
16 class StoppageAlert(alert.Alert): | 18 class StoppageAlert(alert.Alert): |
17 """A stoppage alert is an alert for a Test no longer receiving new points. | 19 """A stoppage alert is an alert for a Test no longer receiving new points. |
18 | 20 |
19 Each StoppageAlert is associated with one Test, so if a test suite gets | 21 Each StoppageAlert is associated with one Test, so if a test suite gets |
20 deprecated or renamed, there may be a set of related StoppageAlerts created. | 22 deprecated or renamed, there may be a set of related StoppageAlerts created. |
21 | 23 |
22 The key for a StoppageAlert is of the form: | 24 The key for a StoppageAlert is of the form: |
23 [("StoppageAlertParent", <test_path>), ("StoppageAlert", <revision>)]. | 25 [("StoppageAlertParent", <test_path>), ("StoppageAlert", <revision>)]. |
24 | 26 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
83 row: A Row entity; the last Row that was put before the stoppage. | 85 row: A Row entity; the last Row that was put before the stoppage. |
84 | 86 |
85 Returns: | 87 Returns: |
86 A new StoppageAlert entity (although this entity has not yet been put. | 88 A new StoppageAlert entity (although this entity has not yet been put. |
87 """ | 89 """ |
88 new_alert = StoppageAlert( | 90 new_alert = StoppageAlert( |
89 parent=ndb.Key('StoppageAlertParent', test.test_path), | 91 parent=ndb.Key('StoppageAlertParent', test.test_path), |
90 id=row.revision, | 92 id=row.revision, |
91 internal_only=test.internal_only, | 93 internal_only=test.internal_only, |
92 sheriff=test.sheriff) | 94 sheriff=test.sheriff) |
95 alert_group.GroupAlerts([new_alert], test.suite_name, 'StoppageAlert') | |
96 grouped_alert_keys = StoppageAlert.query( | |
97 StoppageAlert.group == new_alert.group).fetch(keys_only=True) | |
98 if len(grouped_alert_keys) >= _MAX_GROUP_SIZE: | |
99 # Too many stoppage alerts in this group; we don't want to put any more. | |
100 return None | |
chrisphan
2015/11/06 18:06:42
Does this need to always return an entity?
qyearsley
2015/11/06 18:11:08
Nope, as is in this CL, CreateStoppageAlert decide
| |
93 test.stoppage_alert = new_alert.key | 101 test.stoppage_alert = new_alert.key |
94 test.put() | 102 test.put() |
95 alert_group.GroupAlerts([new_alert], test.suite_name, 'StoppageAlert') | |
96 return new_alert | 103 return new_alert |
97 | 104 |
OLD | NEW |