Skip to content

Commit f68500b

Browse files
committed
Add cancel method for installer
1 parent 0eb6add commit f68500b

3 files changed

Lines changed: 24 additions & 3 deletions

File tree

src/cloud/digitalocean/provisioner.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,12 @@ class Provisioner {
133133
// Find and delete the server with the same name
134134
return this.getDroplet_(name);
135135
}).then((resp :any) => {
136-
this.state_.cloud = {};
137-
this.state_.cloud.vm = resp.droplet;
138-
return this.doRequest_('DELETE', 'droplets/' + resp.droplet.id);
136+
this.state_.cloud = this.state_.cloud || {};
137+
this.state_.cloud.vm = this.state_.cloud.vm || resp.droplet;
138+
// Make sure there are no actions in progress before deleting
139+
return this.waitDigitalOceanActions_();
140+
}).then(() => {
141+
return this.doRequest_('DELETE', 'droplets/' + this.state_.cloud.vm.id);
139142
}).then((resp: any) => {
140143
if (resp.status.startsWith('204')) {
141144
// Wait until server is deleted

src/cloud/install/freedom-module.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
"value": ["string", "number", "string", "string"],
1616
"ret": "object"
1717
},
18+
"cancel": {
19+
"type": "method",
20+
"value": [],
21+
"ret": []
22+
},
1823
"err": {
1924
"message": "string"
2025
},

src/cloud/install/installer.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ const PROGRESS_PREFIX = 'CLOUD_INSTALL_PROGRESS';
2727
// Prefix for status updates.
2828
const 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.
3134
const INITIAL_CONNECTION_INTERVAL_MS = 500;
3235
const MAX_CONNECTION_INTERVAL_MS = 10000;
@@ -36,6 +39,7 @@ const MAX_CONNECTION_INTERVAL_MS = 10000;
3639
// so that we have fewer paths to test.
3740
class 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

145158
export = CloudInstaller;

0 commit comments

Comments
 (0)