1
- use std:: path:: PathBuf ;
2
-
3
1
use crate :: {
4
- client:: { PlaneClient , PlaneClientError } ,
2
+ client:: { sse :: SseStream , PlaneClient , PlaneClientError } ,
5
3
names:: { BackendName , DroneName , Name , ProxyName } ,
6
4
protocol:: { CertManagerRequest , CertManagerResponse , MessageFromProxy , MessageToProxy } ,
7
5
types:: {
8
- BackendStatus , ClusterName , ClusterState , ConnectRequest , DockerExecutorConfig ,
9
- DronePoolName , KeyConfig , Mount , NodeState , SpawnConfig , Subdomain ,
6
+ backend_state:: BackendStatusStreamEntry , BackendStatus , ClusterName , ClusterState ,
7
+ ConnectRequest , DockerExecutorConfig , DronePoolName , KeyConfig , Mount , NodeState ,
8
+ SpawnConfig , Subdomain ,
10
9
} ,
11
10
PLANE_GIT_HASH , PLANE_VERSION ,
12
11
} ;
13
12
use chrono:: Duration ;
14
13
use clap:: { Parser , Subcommand } ;
15
14
use colored:: Colorize ;
15
+ use futures_util:: { Stream , StreamExt } ;
16
+ use std:: path:: PathBuf ;
16
17
use url:: Url ;
17
18
18
19
fn show_error ( error : & PlaneClientError ) {
@@ -156,6 +157,9 @@ pub enum AdminCommand {
156
157
ClusterState {
157
158
cluster : ClusterName ,
158
159
} ,
160
+ BackendStatus {
161
+ backend : BackendName ,
162
+ } ,
159
163
}
160
164
161
165
pub async fn run_admin_command ( opts : AdminOpts ) {
@@ -165,6 +169,23 @@ pub async fn run_admin_command(opts: AdminOpts) {
165
169
}
166
170
}
167
171
172
+ pub async fn print_status_stream (
173
+ mut stream : SseStream < BackendStatusStreamEntry > ,
174
+ until : BackendStatus ,
175
+ ) {
176
+ while let Some ( status) = stream. next ( ) . await {
177
+ println ! (
178
+ "Status: {} at {}" ,
179
+ status. status. to_string( ) . magenta( ) ,
180
+ status. time. 0 . to_string( ) . bright_cyan( )
181
+ ) ;
182
+
183
+ if status. status >= until {
184
+ break ;
185
+ }
186
+ }
187
+ }
188
+
168
189
pub async fn run_admin_command_inner ( opts : AdminOpts ) -> Result < ( ) , PlaneClientError > {
169
190
let client = PlaneClient :: new ( opts. controller ) ;
170
191
@@ -227,19 +248,8 @@ pub async fn run_admin_command_inner(opts: AdminOpts) -> Result<(), PlaneClientE
227
248
}
228
249
229
250
if !immediate {
230
- let mut stream = client. backend_status_stream ( & response. backend_id ) . await ?;
231
-
232
- while let Some ( status) = stream. next ( ) . await {
233
- println ! (
234
- "Status: {} at {}" ,
235
- status. status. to_string( ) . magenta( ) ,
236
- status. time. 0 . to_string( ) . bright_cyan( )
237
- ) ;
238
-
239
- if status. status >= BackendStatus :: Ready {
240
- break ;
241
- }
242
- }
251
+ let stream = client. backend_status_stream ( & response. backend_id ) . await ?;
252
+ print_status_stream ( stream, BackendStatus :: Ready ) . await ;
243
253
}
244
254
}
245
255
AdminCommand :: Terminate {
@@ -259,19 +269,8 @@ pub async fn run_admin_command_inner(opts: AdminOpts) -> Result<(), PlaneClientE
259
269
) ;
260
270
261
271
if !immediate {
262
- let mut stream = client. backend_status_stream ( & backend) . await ?;
263
-
264
- while let Some ( status) = stream. next ( ) . await {
265
- println ! (
266
- "Status: {} at {}" ,
267
- status. status. to_string( ) . magenta( ) ,
268
- status. time. 0 . to_string( ) . bright_cyan( )
269
- ) ;
270
-
271
- if status. status >= BackendStatus :: Terminated {
272
- break ;
273
- }
274
- }
272
+ let stream = client. backend_status_stream ( & backend) . await ?;
273
+ print_status_stream ( stream, BackendStatus :: Terminated ) . await ;
275
274
}
276
275
}
277
276
AdminCommand :: Drain { cluster, drone } => {
@@ -366,6 +365,10 @@ pub async fn run_admin_command_inner(opts: AdminOpts) -> Result<(), PlaneClientE
366
365
let cluster_state = client. cluster_state ( & cluster) . await ?;
367
366
show_cluster_state ( & cluster_state) ;
368
367
}
368
+ AdminCommand :: BackendStatus { backend } => {
369
+ let stream = client. backend_status_stream ( & backend) . await ?;
370
+ print_status_stream ( stream, BackendStatus :: Terminated ) . await ;
371
+ }
369
372
} ;
370
373
371
374
Ok ( ( ) )
0 commit comments