@@ -27,6 +27,9 @@ const PROGRESS_PREFIX = 'CLOUD_INSTALL_PROGRESS';
2727// Prefix for status updates.
2828const STATUS_PREFIX = 'CLOUD_INSTALL_STATUS' ;
2929
30+ // Status indicating that the installer has been canceled.
31+ const CANCELED_STATUS = 'CANCELED' ;
32+
3033// Retry timing for SSH connection establishment.
3134const INITIAL_CONNECTION_INTERVAL_MS = 500 ;
3235const MAX_CONNECTION_INTERVAL_MS = 10000 ;
@@ -36,6 +39,7 @@ const MAX_CONNECTION_INTERVAL_MS = 10000;
3639// so that we have fewer paths to test.
3740class CloudInstaller {
3841 constructor ( private dispatchEvent_ : ( name : string , args : Object ) => void ) { }
42+ private status_ :string = undefined ;
3943
4044 // Runs the install command via SSH, resolving with the invitation URL.
4145 public install = (
@@ -57,6 +61,10 @@ class CloudInstaller {
5761
5862 let numAttempts = 0 ;
5963 return promises . retryWithExponentialBackoff ( ( ) => {
64+ if ( this . status_ === CANCELED_STATUS ) {
65+ log . debug ( 'Canceling cloud installer...' ) ;
66+ return Promise . reject ( new Error ( 'canceled' ) ) ;
67+ }
6068 log . debug ( 'connection attempt %1...' , ( ++ numAttempts ) ) ;
6169 return new Promise < string > ( ( F , R ) => {
6270 const connection = new Client ( ) ;
@@ -88,6 +96,7 @@ class CloudInstaller {
8896 this . dispatchEvent_ ( 'progress' , progress ) ;
8997 }
9098 } else if ( line . indexOf ( STATUS_PREFIX ) === 0 ) {
99+ this . status_ = line ;
91100 this . dispatchEvent_ ( 'status' , line ) ;
92101 }
93102 } ) ;
@@ -140,6 +149,10 @@ class CloudInstaller {
140149 } ) ;
141150 } , MAX_CONNECTION_INTERVAL_MS , INITIAL_CONNECTION_INTERVAL_MS ) ;
142151 }
152+
153+ public cancel = ( ) : void => {
154+ this . status_ = CANCELED_STATUS ;
155+ }
143156}
144157
145158export = CloudInstaller ;
0 commit comments