1
- function populate_data ( data ) {
1
+ import { STATUS_DATA_URL } from "../configuration" ;
2
+
3
+ interface Commit {
4
+ sha : string ;
5
+ date : string ;
6
+ type : "Try" | "Master" ;
7
+ }
8
+
9
+ interface BenchmarkStatus {
10
+ name : string ;
11
+ error : string ;
12
+ }
13
+
14
+ interface Step {
15
+ step : string ;
16
+ is_done : boolean ;
17
+ expected_duration : number ;
18
+ current_progress : number ;
19
+ }
20
+
21
+ /**
22
+ * The `any` types in the interface below were chosen because the types are quite complex
23
+ * on the Rust side (they are modeled with enums encoded in a way that is not so simple to model in
24
+ * TS).
25
+ */
26
+ interface CurrentState {
27
+ artifact : any ;
28
+ progress : [ Step ] ;
29
+ }
30
+
31
+ interface StatusResponse {
32
+ last_commit : Commit | null
33
+ benchmarks : [ BenchmarkStatus ] ,
34
+ missing : [ [ Commit , any ] ] ,
35
+ current : CurrentState | null ,
36
+ most_recent_end : number | null ,
37
+ }
38
+
39
+ function populate_data ( data : StatusResponse ) {
2
40
let state_div = document . querySelector ( "#benchmark-state" ) ;
3
- if ( data . last_commit ) {
41
+ if ( data . last_commit !== null ) {
4
42
let element = document . createElement ( "p" ) ;
5
43
element . innerHTML = `SHA: ${ data . last_commit . sha } , date: ${ data . last_commit . date } ` ;
6
44
state_div . appendChild ( element ) ;
@@ -11,7 +49,7 @@ function populate_data(data) {
11
49
<summary>${ benchmark . name } - error</summary>
12
50
<pre class="benchmark-error"></pre>
13
51
</details>` ;
14
- element . querySelector ( ".benchmark-error" ) . innerText = benchmark . error ;
52
+ element . querySelector < HTMLElement > ( ".benchmark-error" ) . innerText = benchmark . error ;
15
53
state_div . appendChild ( element ) ;
16
54
}
17
55
let missing_div = document . querySelector ( "#data-insert-js" ) ;
@@ -39,9 +77,8 @@ function populate_data(data) {
39
77
tr . appendChild ( td ) ;
40
78
td = document . createElement ( "td" ) ;
41
79
let progress = document . createElement ( "progress" ) ;
42
- progress . setAttribute ( "max" , step . expected_duration ) ;
43
- progress . setAttribute ( "value" , step . is_done ?
44
- step . expected_duration : step . current_progress ) ;
80
+ progress . setAttribute ( "max" , step . expected_duration . toString ( ) ) ;
81
+ progress . setAttribute ( "value" , ( step . is_done ? step . expected_duration : step . current_progress ) . toString ( ) ) ;
45
82
td . appendChild ( progress ) ;
46
83
tr . appendChild ( td ) ;
47
84
td = document . createElement ( "td" ) ;
@@ -75,7 +112,7 @@ function populate_data(data) {
75
112
let end = new Date ( data . most_recent_end * 1000 ) ;
76
113
element . innerHTML = `No current collection in progress. Last one
77
114
finished at ${ end . toLocaleString ( ) } local time,
78
- ${ format_duration ( Math . trunc ( ( new Date ( ) - end ) / 1000 ) ) } ago.` ;
115
+ ${ format_duration ( Math . trunc ( ( Date . now ( ) - end . getTime ( ) ) / 1000 ) ) } ago.` ;
79
116
} else {
80
117
element . innerHTML = "No current collection in progress." ;
81
118
}
@@ -163,16 +200,10 @@ function format_duration(seconds) {
163
200
return s ;
164
201
}
165
202
166
- function addHours ( date , hours ) {
167
- let ret = new Date ( date ) ;
168
- ret . setTime ( ret . getTime ( ) + ( hours * 60 * 60 * 1000 ) ) ;
169
- return ret ;
170
- }
171
-
172
- function make_data ( ) {
173
- fetch ( BASE_URL + "/status_page" , { } ) . then ( function ( response ) {
174
- response . json ( ) . then ( data => populate_data ( data ) ) ;
175
- } ) ;
203
+ async function make_data ( ) {
204
+ const response = await fetch ( STATUS_DATA_URL , { } ) ;
205
+ const data = await response . json ( ) ;
206
+ populate_data ( data ) ;
176
207
}
177
208
178
209
make_data ( ) ;
0 commit comments