New syncing script sometimes schedules a build request on a wrong builder
[WebKit.git] / Websites / perf.webkit.org / public / v3 / models / build-request.js
1 'use strict';
2
3 class BuildRequest extends DataModelObject {
4
5     constructor(id, object)
6     {
7         super(id, object);
8         this._testGroupId = object.testGroupId;
9         console.assert(!object.testGroup || object.testGroup instanceof TestGroup);
10         this._testGroup = object.testGroup;
11         if (this._testGroup)
12             this._testGroup.addBuildRequest(this);
13         console.assert(object.platform instanceof Platform);
14         this._platform = object.platform;
15         console.assert(object.test instanceof Test);
16         this._test = object.test;
17         this._order = object.order;
18         console.assert(object.rootSet instanceof RootSet);
19         this._rootSet = object.rootSet;
20         this._status = object.status;
21         this._statusUrl = object.url;
22         this._buildId = object.build;
23         this._result = null;
24     }
25
26     updateSingleton(object)
27     {
28         console.assert(this._testGroup == object.testGroup);
29         console.assert(this._order == object.order);
30         console.assert(this._rootSet == object.rootSet);
31         this._status = object.status;
32         this._statusUrl = object.url;
33         this._buildId = object.build;
34     }
35
36     testGroupId() { return this._testGroupId; }
37     testGroup() { return this._testGroup; }
38     platform() { return this._platform; }
39     test() { return this._test; }
40     order() { return +this._order; }
41     rootSet() { return this._rootSet; }
42
43     status() { return this._status; }
44     hasFinished() { return this._status == 'failed' || this._status == 'completed' || this._status == 'canceled'; }
45     hasStarted() { return this._status != 'pending'; }
46     isScheduled() { return this._status == 'scheduled'; }
47     isPending() { return this._status == 'pending'; }
48     statusLabel()
49     {
50         switch (this._status) {
51         case 'pending':
52             return 'Waiting to be scheduled';
53         case 'scheduled':
54             return 'Scheduled';
55         case 'running':
56             return 'Running';
57         case 'failed':
58             return 'Failed';
59         case 'completed':
60             return 'Completed';
61         case 'canceled':
62             return 'Canceled';
63         }
64     }
65     statusUrl() { return this._statusUrl; }
66
67     buildId() { return this._buildId; }
68
69     result() { return this._result; }
70     setResult(result)
71     {
72         this._result = result;
73         this._testGroup.didSetResult(this);
74     }
75
76     static fetchForTriggerable(triggerable)
77     {
78         return RemoteAPI.getJSONWithStatus('/api/build-requests/' + triggerable).then(function (data) {
79             return BuildRequest.constructBuildRequestsFromData(data);
80         });
81     }
82
83     static constructBuildRequestsFromData(data)
84     {
85         var rootIdMap = {};
86         for (var root of data['roots']) {
87             rootIdMap[root.id] = root;
88             root.repository = Repository.findById(root.repository);
89         }
90
91         var rootSets = data['rootSets'].map(function (row) {
92             row.roots = row.roots.map(function (rootId) { return rootIdMap[rootId]; });
93             return RootSet.ensureSingleton(row.id, row);
94         });
95
96         return data['buildRequests'].map(function (rawData) {
97             rawData.platform = Platform.findById(rawData.platform);
98             rawData.test = Test.findById(rawData.test);
99             rawData.testGroupId = rawData.testGroup;
100             rawData.testGroup = TestGroup.findById(rawData.testGroup);
101             rawData.rootSet = RootSet.findById(rawData.rootSet);
102             return BuildRequest.ensureSingleton(rawData.id, rawData);
103         });
104     }
105 }
106
107 if (typeof module != 'undefined')
108     module.exports.BuildRequest = BuildRequest;