|
1 |
| -import {isObject, isString} from "../../utils/getType"; |
| 1 | +type BenchmarkRequestStatusComplete = { |
| 2 | + state: "completed"; |
| 3 | + completedAt: string; |
| 4 | + duration: number; // time in milliseconds |
| 5 | +}; |
2 | 6 |
|
3 |
| -type CommitTypeMaster = { |
4 |
| - sha: string; |
5 |
| - parent_sha: string; |
6 |
| - pr: number; |
| 7 | +type BenchmarkRequestStatusInProgress = { |
| 8 | + state: "in_progress"; |
7 | 9 | };
|
8 | 10 |
|
9 |
| -type CommitTypeRelease = { |
10 |
| - tag: string; |
| 11 | +type BenchmarkRequestStatusArtifactsReady = { |
| 12 | + state: "artifacts_ready"; |
11 | 13 | };
|
12 | 14 |
|
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; |
15 | 23 | parent_sha: string | null;
|
16 | 24 | pr: number;
|
17 | 25 | };
|
18 | 26 |
|
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; |
21 | 43 |
|
22 | 44 | 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[]; |
36 | 52 | };
|
37 | 53 |
|
38 | 54 | 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[]; |
46 | 60 | profiles: string;
|
| 61 | + errors: string[]; |
47 | 62 | };
|
48 | 63 |
|
49 | 64 | 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[]; |
57 | 70 | profiles: string;
|
| 71 | + errors: string[]; |
58 | 72 | };
|
59 | 73 |
|
60 |
| -type BenchmarkRequest = |
| 74 | +export type BenchmarkRequest = |
61 | 75 | | BenchmarkRequestComplete
|
62 | 76 | | BenchmarkRequestInProgress
|
63 | 77 | | BenchmarkRequestArtifactsReady;
|
64 | 78 |
|
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 | +}; |
100 | 82 |
|
101 | 83 | export type BenchmarkJobStatusInProgress = {
|
102 |
| - started_at: string; |
103 |
| - collector_name: string; |
| 84 | + state: "in_progress"; |
| 85 | + startedAt: string; |
| 86 | + collectorName: string; |
104 | 87 | };
|
105 | 88 |
|
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; |
111 | 94 | };
|
112 | 95 |
|
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; |
115 | 108 |
|
116 | 109 | export type BenchmarkJob = {
|
117 |
| - id: number; |
118 | 110 | target: string;
|
119 | 111 | 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 | +}; |
150 | 119 |
|
151 | 120 | export type CollectorConfig = {
|
152 | 121 | name: string;
|
153 | 122 | 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[]; |
158 | 132 | };
|
159 | 133 |
|
160 | 134 | 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[]; |
164 | 138 | queue: BenchmarkRequest[];
|
165 | 139 | };
|
0 commit comments