status-page: fix race condition in initialization. (#94)
Due to the fact that loading state text is inserted on window onload, this insertion can potentially happen **after** all other async actions are already finished and thus replace the actual data. This fix makes sure that requests are triggered after onload is done.
Marek Fajkus committed
Jan 8, 2020 at 09:07 UTC
ae96158c4d5cc15a5bfb9e85ff924941bddc9973
1 file changed
+11
-5
delft/eris/status-page/status.js
+11
-5
@@ -1,7 +1,12 @@
1
-window.onload = (_) => {
2
- var tbody = document.getElementById("channel-status");
3
- tbody.innerHTML = "<tr><td class='jsfallback' colspan='5'>Loading data from Prometheus...</td></tr>";
4
-};
1
+function init() {
2
+ return new Promise(resolve => {
3
+ window.onload = () => {
4
+ var tbody = document.getElementById("channel-status");
5
+ tbody.innerHTML = "<tr><td class='jsfallback' colspan='5'>Loading data from Prometheus...</td></tr>";
6
+ resolve();
7
+ };
8
+ });
9
+}
10
11
function aggregateByChannel(result) {
12
return result.reduce((acc, {
@@ -119,7 +124,8 @@ function cmp_channels(left, right) {
124
return normalize_channel(left) < normalize_channel(right)
125
}
126
122
-Promise.all([revisionData, updateTimeData, jobsetData])
127
+init()
128
+ .then(() => Promise.all([revisionData, updateTimeData, jobsetData]))
129
.then(([revisions, update_times, jobsets]) => {
130
var combined = [];
131