One more case of incorrect comparison in recordpatchevent.py
[WebKit-https.git] / Tools / QueueStatusServer / loggers / recordpatchevent.py
1 # Copyright (C) 2013 Google Inc. All rights reserved.
2 # Copyright (C) 2014 Apple Inc. All rights reserved.
3 #
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are
6 # met:
7 #
8 #     * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
10 #     * Redistributions in binary form must reproduce the above
11 # copyright notice, this list of conditions and the following disclaimer
12 # in the documentation and/or other materials provided with the
13 # distribution.
14 #     * Neither the name of Google Inc. nor the names of its
15 # contributors may be used to endorse or promote products derived from
16 # this software without specific prior written permission.
17 #
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30 from config.logging import queue_log_duration
31 from model.patchlog import PatchLog
32 from model.queuelog import QueueLog
33 from model.warninglog import WarningLog
34
35
36 class RecordPatchEvent(object):
37     @classmethod
38     def added(cls, attachment_id, queue_name):
39         PatchLog.lookup(attachment_id, queue_name)
40         queue_log = QueueLog.get_current(queue_name, queue_log_duration)
41         if queue_log.update_max_patches_waiting():
42             queue_log.put()
43
44     @classmethod
45     def started(cls, attachment_id, queue_name, bot_id=None):
46         patch_log = PatchLog.lookup_if_exists(attachment_id, queue_name)
47         if not patch_log:
48             WarningLog.record("patchlog missing", "In started event.", attachment_id, queue_name, bot_id)
49             return
50
51         if bot_id:
52             patch_log.bot_id = bot_id
53
54         # An existing wait_duration implies the patch had been started previously and is
55         # being picked up again because it had expired, or was released.
56         if patch_log.wait_duration is not None:
57             patch_log.retry_count += 1
58             patch_log.put()
59
60             queue_log = QueueLog.get_current(queue_name, queue_log_duration)
61             queue_log.patch_retry_count += 1
62             queue_log.put()
63         else:
64             patch_log.calculate_wait_duration()
65             patch_log.put()
66
67             queue_log = QueueLog.get_current(queue_name, queue_log_duration)
68             queue_log.patch_wait_durations.append(patch_log.wait_duration)
69             queue_log.put()
70
71     @classmethod
72     def stopped(cls, attachment_id, queue_name, status_message, bot_id=None):
73         patch_log = PatchLog.lookup_if_exists(attachment_id, queue_name)
74         if not patch_log:
75             WarningLog.record("patchlog missing", "In stopped event.", attachment_id, queue_name, bot_id)
76             return
77
78         if patch_log.wait_duration is None:
79             WarningLog.record("patchlog wait duration missing", "In stopped event.", attachment_id, queue_name, bot_id)
80             return
81
82         if not patch_log.finished:
83             if bot_id:
84                 patch_log.bot_id = bot_id
85             patch_log.finished = True
86             patch_log.calculate_process_duration()
87             patch_log.latest_message = status_message
88             patch_log.put()
89
90             queue_log = QueueLog.get_current(queue_name, queue_log_duration)
91             queue_log.patch_process_durations.append(patch_log.process_duration)
92             queue_log.put()
93
94     @classmethod
95     def updated(cls, attachment_id, queue_name, status_message, bot_id=None):
96         patch_log = PatchLog.lookup_if_exists(attachment_id, queue_name)
97         if not patch_log:
98             WarningLog.record("patchlog missing", "In updated event.", attachment_id, queue_name, bot_id)
99             return
100
101         if bot_id:
102             patch_log.bot_id = bot_id
103         patch_log.status_update_count += 1
104         patch_log.latest_message = status_message
105         patch_log.put()
106
107         queue_log = QueueLog.get_current(queue_name, queue_log_duration)
108         queue_log.status_update_count += 1
109         queue_log.put()
110