1- import { Flags } from '@oclif/core'
2- import { MultiBar , Presets , SingleBar } from 'cli-progress'
3-
4- import { ScCommand } from '../../../sc-command.js'
5- import { AllOperationResponse , EventBrokerListApiResponse , OperationData , OperationResponse } from '../../../types/broker.js'
6- import { renderTable , sleep } from '../../../util/internal.js'
7- import { ScConnection } from '../../../util/sc-connection.js'
1+ import { Flags } from '@oclif/core'
2+ import { MultiBar , Presets , SingleBar } from 'cli-progress'
3+
4+ import { ScCommand } from '../../../sc-command.js'
5+ import {
6+ EventBrokerAllOperationsApiResponse ,
7+ EventBrokerListApiResponse ,
8+ EventBrokerOperationApiResponse ,
9+ EventBrokerOperationDetail ,
10+ } from '../../../types/broker.js'
11+ import { renderTable , sleep } from '../../../util/internal.js'
12+ import { ScConnection } from '../../../util/sc-connection.js'
813
914export default class MissionctrlBrokerOpstatus extends ScCommand < typeof MissionctrlBrokerOpstatus > {
1015 static override args = { }
@@ -29,16 +34,18 @@ export default class MissionctrlBrokerOpstatus extends ScCommand<typeof Missionc
2934 } ) ,
3035 'show-progress' : Flags . boolean ( {
3136 char : 'p' ,
32- description : 'Displays a status bar of the in-progress operations. The command will wait for completion of each step of the operation.'
37+ description :
38+ 'Displays a status bar of the in-progress operations. The command will wait for completion of each step of the operation.' ,
3339 } ) ,
3440 'wait-ms' : Flags . integer ( {
3541 char : 'w' ,
36- description : 'The milliseconds to wait between API calls for checking progress of the operation. Default is 5000 ms.'
42+ description :
43+ 'The milliseconds to wait between API calls for checking progress of the operation. Default is 5000 ms.' ,
3744 } ) ,
3845 }
3946
40- public async run ( ) : Promise < OperationData [ ] > {
41- const { flags } = await this . parse ( MissionctrlBrokerOpstatus )
47+ public async run ( ) : Promise < EventBrokerOperationDetail [ ] > {
48+ const { flags} = await this . parse ( MissionctrlBrokerOpstatus )
4249
4350 const name = flags . name ?? ''
4451 let brokerId = flags [ 'broker-id' ] ?? ''
@@ -56,23 +63,25 @@ export default class MissionctrlBrokerOpstatus extends ScCommand<typeof Missionc
5663 // API call to get broker by name
5764 apiUrl += `?customAttributes=name=="${ name } "`
5865 const resp = await conn . get < EventBrokerListApiResponse > ( apiUrl )
59- // FUTURE: show status of multiple brokers operations that match the name
66+ // FUTURE: show status of multiple brokers operations that match the name
6067 if ( resp . data . length === 0 ) {
6168 this . error ( `No brokers found with name: ${ name } .` )
6269 } else if ( resp . data . length > 1 ) {
63- this . error ( `Multiple broker services found with: ${ name } . Exactly one broker service must match the provided name.` )
70+ this . error (
71+ `Multiple broker services found with: ${ name } . Exactly one broker service must match the provided name.` ,
72+ )
6473 } else {
6574 brokerId = resp . data [ 0 ] ?. id
6675 }
6776 }
6877
6978 // API call to retrieve status of the broker operation
7079 apiUrl = `/missionControl/eventBrokerServices/${ brokerId } /operations`
71-
72- const resp = await conn . get < AllOperationResponse > ( apiUrl )
80+
81+ const resp = await conn . get < EventBrokerAllOperationsApiResponse > ( apiUrl )
7382 const opStatusArray = [
7483 [ 'Operation Id' , 'Operation Type' , 'Status' , 'Created Time' , 'Completed Time' ] ,
75- ...resp . data . map ( ( item : OperationData ) => [
84+ ...resp . data . map ( ( item : EventBrokerOperationDetail ) => [
7685 item . id ,
7786 item . operationType ,
7887 item . status ,
@@ -85,42 +94,51 @@ export default class MissionctrlBrokerOpstatus extends ScCommand<typeof Missionc
8594 this . log ( renderTable ( opStatusArray ) )
8695
8796 // If show-progress flag is set, display progress bars for each operation
88- if ( showProgress && resp . data . length > 0 ) {
97+ if ( showProgress && resp . data . length > 0 ) {
8998 // Create progress bar for each operation
90- const multiProgressBar = new MultiBar ( {
91- clearOnComplete : false ,
92- format : ' {bar} | {operationType} | {value}/{total}' ,
93- hideCursor : true ,
94- } , Presets . shades_classic )
95-
99+ const multiProgressBar = new MultiBar (
100+ {
101+ clearOnComplete : false ,
102+ format : ' {bar} | {operationType} | {value}/{total}' ,
103+ hideCursor : true ,
104+ } ,
105+ Presets . shades_classic ,
106+ )
107+
96108 // Get the initial progress for each operation
97109 const progressBars : [ string , SingleBar ] [ ] = [ ]
98110 let completedOperations = 0
99111 let allCompleted = false
100112 for ( const operationData of resp . data ) {
101113 const opStatusApiUrl = `/missionControl/eventBrokerServices/${ brokerId } /operations/${ operationData . id } ?expand=progressLogs`
102114 // eslint-disable-next-line no-await-in-loop
103- const opStatusResp = await conn . get < OperationResponse > ( opStatusApiUrl )
104- this . debug ( `Operation ID: ${ operationData . id } , Type: ${ operationData . operationType } , Status: ${ operationData . status } ` )
115+ const opStatusResp = await conn . get < EventBrokerOperationApiResponse > ( opStatusApiUrl )
116+ this . debug (
117+ `Operation ID: ${ operationData . id } , Type: ${ operationData . operationType } , Status: ${ operationData . status } ` ,
118+ )
105119 if ( opStatusResp . data . progressLogs ) {
106120 const numSteps = opStatusResp . data . progressLogs . length
107121 // start a new progress bar for the operation with a total value of size of the steps
108- const progressBar = multiProgressBar . create ( numSteps , 0 , { operationType : operationData . operationType } )
122+ const progressBar = multiProgressBar . create ( numSteps , 0 , { operationType : operationData . operationType } )
109123 // Update the progress with the steps completed
110- const completedNumSteps = opStatusResp . data . progressLogs . filter ( log => log . status === 'success' ) . length
124+ const completedNumSteps = opStatusResp . data . progressLogs . filter ( ( log ) => log . status === 'success' ) . length
111125 progressBar . update ( completedNumSteps )
112- if ( completedNumSteps === numSteps || opStatusResp . data . status === 'SUCCEEDED' || opStatusResp . data . status === 'FAILED' ) {
126+ if (
127+ completedNumSteps === numSteps ||
128+ opStatusResp . data . status === 'SUCCEEDED' ||
129+ opStatusResp . data . status === 'FAILED'
130+ ) {
113131 completedOperations += 1
114132 progressBar . stop ( )
115133 }
116-
134+
117135 // Add the operation ID and progress bar to the list
118136 progressBars . push ( [ operationData . id , progressBar ] )
119137 }
120138 }
121139
122140 // Check if all operations are completed
123- if ( completedOperations === progressBars . length ) {
141+ if ( completedOperations === progressBars . length ) {
124142 allCompleted = true
125143 }
126144
@@ -132,29 +150,37 @@ export default class MissionctrlBrokerOpstatus extends ScCommand<typeof Missionc
132150 // eslint-disable-next-line no-await-in-loop
133151 allCompleted = await this . pollAllOperationStatus ( conn , brokerId , progressBars )
134152 }
135-
153+
136154 multiProgressBar . stop ( )
137155 this . log ( ) // Add a new line for better readability
138156 }
139157
140158 return resp . data
141159 }
142160
143- private async pollAllOperationStatus ( conn : ScConnection , brokerId : string , progressBars : [ string , SingleBar ] [ ] ) : Promise < boolean > {
161+ private async pollAllOperationStatus (
162+ conn : ScConnection ,
163+ brokerId : string ,
164+ progressBars : [ string , SingleBar ] [ ] ,
165+ ) : Promise < boolean > {
144166 let completedOperations = 0
145167 let allCompleted = false
146168 // For each operation, get the latest status and update the progress bar
147169 for ( const [ operationId , progressBar ] of progressBars ) {
148170 const opStatusApiUrl = `/missionControl/eventBrokerServices/${ brokerId } /operations/${ operationId } ?expand=progressLogs`
149171 // eslint-disable-next-line no-await-in-loop
150- const opStatusResp = await conn . get < OperationResponse > ( opStatusApiUrl )
172+ const opStatusResp = await conn . get < EventBrokerOperationApiResponse > ( opStatusApiUrl )
151173 if ( opStatusResp . data . progressLogs ) {
152174 const numSteps = opStatusResp . data . progressLogs . length
153- const completedNumSteps = opStatusResp . data . progressLogs . filter ( log => log . status === 'success' ) . length
175+ const completedNumSteps = opStatusResp . data . progressLogs . filter ( ( log ) => log . status === 'success' ) . length
154176 // Update progress bar
155177 progressBar . setTotal ( numSteps )
156178 progressBar . update ( completedNumSteps )
157- if ( completedNumSteps === numSteps || opStatusResp . data . status === 'SUCCEEDED' || opStatusResp . data . status === 'FAILED' ) {
179+ if (
180+ completedNumSteps === numSteps ||
181+ opStatusResp . data . status === 'SUCCEEDED' ||
182+ opStatusResp . data . status === 'FAILED'
183+ ) {
158184 completedOperations += 1
159185 progressBar . stop ( )
160186 }
@@ -164,10 +190,10 @@ export default class MissionctrlBrokerOpstatus extends ScCommand<typeof Missionc
164190 }
165191
166192 // Check if all operations are completed
167- if ( completedOperations === progressBars . length ) {
193+ if ( completedOperations === progressBars . length ) {
168194 allCompleted = true
169195 }
170196
171197 return allCompleted
172198 }
173- }
199+ }
0 commit comments