build.webkit.org/dashboard: Switch EWS view to using actual retry count
[WebKit-https.git] / Tools / BuildSlaveSupport / build.webkit.org-config / public_html / dashboard / Scripts / EWSQueue.js
1 /*
2  * Copyright (C) 2013, 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
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 EWSQueue = function(ews, id, info)
27 {
28     BaseObject.call(this);
29
30     console.assert(ews);
31     console.assert(id);
32
33     this.ews = ews;
34     this.id = id;
35     this.title = info.title || "\xa0";
36
37     this.platform = info.platform.name || "unknown";
38 };
39
40 BaseObject.addConstructorFunctions(EWSQueue);
41
42 EWSQueue.Event = {
43     Updated: "updated"
44 };
45
46 EWSQueue.prototype = {
47     constructor: EWSQueue,
48     __proto__: BaseObject.prototype,
49
50     get statusPageURL()
51     {
52         return this.ews.queueStatusURL(this.id);
53     },
54
55     get chartsPageURL()
56     {
57         return this._chartsPageURL;
58     },
59
60     get patchCount()
61     {
62         return this._patchCount;
63     },
64
65     get loadedDetailedStatus()
66     {
67         return this._loadedDetailedStatus;
68     },
69
70     get patches()
71     {
72         console.assert(this._loadedDetailedStatus);
73         return this._queue;
74     },
75
76     get bots()
77     {
78         console.assert(this._loadedDetailedStatus);
79         return this._bots;
80     },
81
82     update: function()
83     {
84         this._loadedDetailedStatus = false;
85
86         JSON.load(this.ews.jsonQueueLengthURL(this.id), function(data) {
87             var newPatchCount = data.queue_length;
88             if (this._patchCount == newPatchCount)
89                 return;
90             this._patchCount = newPatchCount;
91             this.dispatchEventToListeners(EWSQueue.Event.Updated, null);
92         }.bind(this));
93     },
94
95     loadDetailedStatus: function(callback)
96     {
97         JSON.load(this.ews.jsonQueueStatusURL(this.id), function(data) {
98             this._queue = [];
99             for (var i = 0, end = data.queue.length; i < end; ++i) {
100                 var patch = data.queue[i];
101                 var activeSinceTime = patch.active_since ? Date.parse(patch.active_since) : 0;
102                 this._queue.push({
103                     attachmentID: patch.attachment_id,
104                     statusPageURL: patch.status_page,
105                     latestMessage: patch.latest_message,
106                     latestMessageTime: patch.latest_message_time ? new Date(patch.latest_message_time) : null,
107                     detailedResultsURLForLatestMessage: patch.latest_results,
108                     retryCount: patch.retry_count,
109                     active: patch.active,
110                     activeSince: new Date(activeSinceTime),
111                 });
112             }
113
114             this._bots = [];
115             for (var i = 0, end = data.bots.length; i < end; ++i) {
116                 var bot = data.bots[i];
117                 var latestMessageTime = bot.latest_message_time ? Date.parse(bot.latest_message_time) : 0;
118
119                 var oneDayInMilliseconds = 24 * 60 * 60 * 1000;
120                 var botIsCurrentlyActive = Date.now() < latestMessageTime + oneDayInMilliseconds;
121                 if (!botIsCurrentlyActive)
122                     continue;
123
124                 // Sometimes (rarely), there are status messages with an empty bot name added to the database.
125                 if (!bot.bot_id.length)
126                     bot.bot_id = "<empty name>";
127
128                 this._bots.push({
129                     id: bot.bot_id,
130                     statusPageURL: bot.status_page,
131                     latestMessageTime: new Date(latestMessageTime),
132                 });
133             }
134
135             console.assert(this.statusPageURL === data.status_page);
136             this._chartsPageURL = data.charts_page;
137
138             this._loadedDetailedStatus = true;
139             callback();
140         }.bind(this));
141     },
142 };