@@ -20,14 +20,15 @@ export default class LuisTrainRun extends Command {
2020 subscriptionKey : flags . string ( { description : '(required) LUIS cognitive services subscription key (default: config:LUIS:subscriptionKey)' } ) ,
2121 appId : flags . string ( { description : '(required) LUIS application Id (defaults to config:LUIS:appId)' } ) ,
2222 versionId : flags . string ( { description : '(required) Version to show training status (defaults to config:LUIS:versionId)' } ) ,
23+ wait : flags . boolean ( { description : 'Wait until training complete and then display status' } ) ,
2324 }
2425
2526 async run ( ) {
2627 const { flags} = this . parse ( LuisTrainRun )
2728 const flagLabels = Object . keys ( LuisTrainRun . flags )
2829 const configDir = this . config . configDir
2930
30- let { endpoint, subscriptionKey, appId, versionId} = await utils . processInputs ( flags , flagLabels , configDir )
31+ let { endpoint, subscriptionKey, appId, versionId, wait } = await utils . processInputs ( flags , flagLabels , configDir )
3132
3233 const requiredProps = { endpoint, subscriptionKey, appId, versionId}
3334 utils . validateRequiredProps ( requiredProps )
@@ -40,9 +41,43 @@ export default class LuisTrainRun extends Command {
4041 await utils . writeToConsole ( trainingRequestStatus )
4142 this . log ( '\nTraining request successfully issued' )
4243 }
44+ if ( wait ) {
45+ this . log ( 'checking training status...' )
46+ return this . checkTrainingStatus ( client , appId , versionId )
47+ }
4348 } catch ( err ) {
4449 throw new CLIError ( `Failed to issue training request: ${ err } ` )
4550 }
4651 }
4752
53+ timeout ( ms : number ) {
54+ // tslint:disable-next-line no-string-based-set-timeout
55+ return new Promise ( ( resolve : any ) => setTimeout ( resolve , ms ) )
56+ }
57+
58+ async checkTrainingStatus ( client : any , appId : string , versionId : string ) {
59+ try {
60+ const trainingStatusData = await client . train . getStatus ( appId , versionId )
61+ const inProgress = trainingStatusData . filter ( ( model : any ) => {
62+ if ( model . details && model . details . status ) {
63+ return model . details . status === 'InProgress' || model . details . status === 'Queued'
64+ }
65+ } )
66+ if ( inProgress . length > 0 ) {
67+ await this . timeout ( 1000 )
68+ await this . checkTrainingStatus ( client , appId , versionId )
69+ } else {
70+ let completionMssg = ''
71+ trainingStatusData . map ( ( model : any ) => {
72+ if ( model . details && model . details . status && model . details . status === 'Fail' ) {
73+ completionMssg += `Training failed for model id ${ model . modelId } . Failure reason: ${ model . details . failureReason } \n`
74+ }
75+ } )
76+ this . log ( `${ completionMssg } Training is complete` )
77+ }
78+ } catch ( err ) {
79+ throw new CLIError ( err )
80+ }
81+ }
82+
4883}
0 commit comments