Skip to content

Commit 5d0a107

Browse files
committed
Use camelcase for all of the objects in the JSON blob, update typescript types
1 parent c04d76d commit 5d0a107

File tree

3 files changed

+110
-133
lines changed

3 files changed

+110
-133
lines changed
Lines changed: 95 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -1,165 +1,139 @@
1-
import {isObject, isString} from "../../utils/getType";
1+
type BenchmarkRequestStatusComplete = {
2+
state: "completed";
3+
completedAt: string;
4+
duration: number; // time in milliseconds
5+
};
26

3-
type CommitTypeMaster = {
4-
sha: string;
5-
parent_sha: string;
6-
pr: number;
7+
type BenchmarkRequestStatusInProgress = {
8+
state: "in_progress";
79
};
810

9-
type CommitTypeRelease = {
10-
tag: string;
11+
type BenchmarkRequestStatusArtifactsReady = {
12+
state: "artifacts_ready";
1113
};
1214

13-
type CommitTypeTry = {
14-
sha: string;
15+
export type BenchmarkRequestStatus =
16+
| BenchmarkRequestStatusComplete
17+
| BenchmarkRequestStatusInProgress
18+
| BenchmarkRequestStatusArtifactsReady;
19+
20+
type BenchmarkRequestTypeTry = {
21+
type: "Try";
22+
tag: string | null;
1523
parent_sha: string | null;
1624
pr: number;
1725
};
1826

19-
export type CommitType = CommitTypeRelease | CommitTypeMaster | CommitTypeTry;
20-
export type CommitTypeString = "Master" | "Try" | "Release";
27+
type BenchmarkRequestTypeMaster = {
28+
type: "Master";
29+
tag: string;
30+
parent_sha: string;
31+
pr: number;
32+
};
33+
34+
type BenchmarkRequestTypeRelease = {
35+
type: "Try";
36+
tag: string;
37+
};
38+
39+
type BenchmarkRequestType =
40+
| BenchmarkRequestTypeTry
41+
| BenchmarkRequestTypeMaster
42+
| BenchmarkRequestTypeRelease;
2143

2244
export type BenchmarkRequestComplete = {
23-
commit_type: {
24-
[K in CommitTypeString]: CommitType;
25-
};
26-
commit_date: string | null;
27-
created_at: string | null;
28-
status: {
29-
Completed: {
30-
completed_at: string;
31-
duration_ms: number;
32-
};
33-
};
34-
backends: string;
35-
profile: string;
45+
status: BenchmarkRequestStatusComplete;
46+
requestType: BenchmarkRequestType;
47+
commitDate: string | null;
48+
createdAt: string | null;
49+
backends: string[];
50+
profiles: string;
51+
errors: string[];
3652
};
3753

3854
export type BenchmarkRequestInProgress = {
39-
commit_type: {
40-
[K in CommitTypeString]: CommitType;
41-
};
42-
commit_date: string | null;
43-
created_at: string | null;
44-
status: "InProgress";
45-
backends: string;
55+
status: BenchmarkRequestStatusInProgress;
56+
requestType: BenchmarkRequestType;
57+
commitDate: string | null;
58+
createdAt: string | null;
59+
backends: string[];
4660
profiles: string;
61+
errors: string[];
4762
};
4863

4964
export type BenchmarkRequestArtifactsReady = {
50-
commit_type: {
51-
[K in CommitTypeString]: CommitType;
52-
};
53-
commit_date: string | null;
54-
created_at: string | null;
55-
status: "ArtifactsReady";
56-
backends: string;
65+
status: BenchmarkRequestStatusArtifactsReady;
66+
requestType: BenchmarkRequestType;
67+
commitDate: string | null;
68+
createdAt: string | null;
69+
backends: string[];
5770
profiles: string;
71+
errors: string[];
5872
};
5973

60-
type BenchmarkRequest =
74+
export type BenchmarkRequest =
6175
| BenchmarkRequestComplete
6276
| BenchmarkRequestInProgress
6377
| BenchmarkRequestArtifactsReady;
6478

65-
export function isMasterBenchmarkRequest(
66-
commitType: Object
67-
): commitType is {["Master"]: CommitTypeMaster} {
68-
return "Master" in commitType;
69-
}
70-
71-
export function isReleaseBenchmarkRequest(
72-
commitType: Object
73-
): commitType is {["Release"]: CommitTypeRelease} {
74-
return "Release" in commitType;
75-
}
76-
77-
export function isTryBenchmarkRequest(
78-
commitType: Object
79-
): commitType is {["Try"]: CommitTypeTry} {
80-
return "Try" in commitType;
81-
}
82-
83-
export function isArtifactsReadyBenchmarkRequest(
84-
req: BenchmarkRequest
85-
): req is BenchmarkRequestArtifactsReady {
86-
return isString(req.status) && req.status === "ArtifactsReady";
87-
}
88-
89-
export function isInProgressBenchmarkRequest(
90-
req: BenchmarkRequest
91-
): req is BenchmarkRequestInProgress {
92-
return isString(req.status) && req.status === "InProgress";
93-
}
94-
95-
export function isCompleteBenchmarkRequest(
96-
req: BenchmarkRequest
97-
): req is BenchmarkRequestComplete {
98-
return isObject(req.status) && "Completed" in req.status;
99-
}
79+
export type BenchmarkJobStatusQueued = {
80+
state: "queued";
81+
};
10082

10183
export type BenchmarkJobStatusInProgress = {
102-
started_at: string;
103-
collector_name: string;
84+
state: "in_progress";
85+
startedAt: string;
86+
collectorName: string;
10487
};
10588

106-
export type BenchmarkJobStatusCompleted = {
107-
started_at: string;
108-
completed_at: string;
109-
collector_name: string;
110-
success: boolean;
89+
export type BenchmarkJobStatusFailed = {
90+
state: "failed";
91+
startedAt: string;
92+
completedAt: string;
93+
collectorName: string;
11194
};
11295

113-
export type BenchmarkJobStatusString = "InProgress" | "Completed";
114-
export type BenchmarkJobStatusQueued = "Queued";
96+
export type BenchmarkJobStatusSuccess = {
97+
state: "success";
98+
startedAt: string;
99+
completedAt: string;
100+
collectorName: string;
101+
};
102+
103+
export type BenchmarkJobStatus =
104+
| BenchmarkJobStatusSuccess
105+
| BenchmarkJobStatusFailed
106+
| BenchmarkJobStatusInProgress
107+
| BenchmarkJobStatusQueued;
115108

116109
export type BenchmarkJob = {
117-
id: number;
118110
target: string;
119111
backend: string;
120-
request_tag: string;
121-
benchmark_set: number;
122-
created_at: string;
123-
status:
124-
| BenchmarkJobStatusQueued
125-
| {
126-
[K in BenchmarkJobStatusQueued]:
127-
| BenchmarkJobStatusInProgress
128-
| BenchmarkJobStatusCompleted;
129-
};
130-
deque_counter: number;
131-
};
132-
133-
export function isQueuedBenchmarkJob(
134-
status: unknown
135-
): status is BenchmarkJobStatusQueued {
136-
return isString(status) && status === "Queued";
137-
}
138-
139-
export function isInProgressBenchmarkJob(
140-
status: unknown
141-
): status is {["InProgress"]: BenchmarkJobStatusInProgress} {
142-
return isObject(status) && "InProgress" in status;
143-
}
144-
145-
export function isCompletedBenchmarkJob(
146-
status: unknown
147-
): status is {["Completed"]: BenchmarkJobStatusCompleted} {
148-
return isObject(status) && "Completed" in status;
149-
}
112+
profile: string;
113+
requestTag: string;
114+
benchmarkSet: number;
115+
createdAt: string;
116+
status: BenchmarkJobStatus;
117+
dequeCounter: number;
118+
};
150119

151120
export type CollectorConfig = {
152121
name: string;
153122
target: string;
154-
benchmark_set: number;
155-
is_active: boolean;
156-
last_heartbeat_at: string;
157-
date_added: string;
123+
benchmarkSet: number;
124+
isActive: boolean;
125+
lastHeartbeatAt: string;
126+
dateAdded: string;
127+
};
128+
129+
export type StatusResponseInProgress = {
130+
request: BenchmarkRequestInProgress;
131+
jobs: BenchmarkJob[];
158132
};
159133

160134
export type StatusResponse = {
161-
completed: [BenchmarkRequestComplete, string[]][];
162-
in_progress: [BenchmarkRequestInProgress, BenchmarkJob[]][];
163-
collector_configs: CollectorConfig[];
135+
completed: BenchmarkRequestComplete[];
136+
inProgress: StatusResponseInProgress[];
137+
collectorConfigs: CollectorConfig[];
164138
queue: BenchmarkRequest[];
165139
};

site/frontend/src/pages/status_new/page.vue

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const loading = ref(true);
1515
const dataNew: Ref<StatusResponse | null> = ref(null);
1616
1717
function statusClass(c: CollectorConfig): string {
18-
return c.is_active ? "active" : "inactive";
18+
return c.isActive ? "active" : "inactive";
1919
}
2020
2121
loadStatusNew(loading);
@@ -34,27 +34,32 @@ loadStatusNew(loading);
3434

3535
<div class="grid">
3636
<div
37-
v-for="c in dataNew.collector_configs"
37+
v-for="c in dataNew.collectorConfigs"
3838
:key="c.name + c.target"
3939
class="card"
4040
>
4141
<div>
4242
<div class="header">
43-
<div class="name">{{ c.name }}:</div>
44-
<div class="status" :class="statusClass(c)">
45-
{{ c.is_active ? "Active" : "Inactive" }}
43+
<div class="name">
44+
<strong>{{ c.name }}</strong>
45+
</div>
46+
<div>
47+
<strong>Status:</strong>
48+
<span class="status" :class="statusClass(c)">
49+
{{ c.isActive ? "Active" : "Inactive" }}
50+
</span>
4651
</div>
4752
</div>
4853
<div class="meta">
4954
<div><strong>Target:</strong> {{ c.target }}</div>
50-
<div><strong>Benchmark Set:</strong> #{{ c.benchmark_set }}</div>
55+
<div><strong>Benchmark Set:</strong> #{{ c.benchmarkSet }}</div>
5156
<div>
5257
<strong>Last Heartbeat:</strong>
53-
{{ c.last_heartbeat_at }}
58+
{{ c.lastHeartbeatAt }}
5459
</div>
5560
<div>
5661
<strong>Date Added:</strong>
57-
{{ c.date_added }}
62+
{{ c.dateAdded }}
5863
</div>
5964
</div>
6065
</div>
@@ -103,16 +108,13 @@ loadStatusNew(loading);
103108
}
104109
105110
.header {
106-
display: flex;
107-
align-items: center;
108111
}
109112
110113
.status {
111-
padding: 2px 8px;
114+
padding: 2px 8px 2px 0px;
112115
border-radius: 20px;
113116
font-size: 0.75rem;
114117
width: 50px;
115-
font-weight: bold;
116118
}
117119
118120
.status.active {

site/src/api.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,7 @@ pub mod status_new {
466466
}
467467

468468
#[derive(Serialize, Debug)]
469+
#[serde(rename_all = "camelCase")]
469470
pub struct Response {
470471
/// Completed requests alongside any errors
471472
pub completed: Vec<BenchmarkRequestUi>,

0 commit comments

Comments
 (0)