Loop until box receives an update

This commit is contained in:
Girish Ramakrishnan 2015-07-16 15:05:06 -07:00
parent 41fc20b1a5
commit 6b7f9e5b9a
1 changed files with 10 additions and 3 deletions

View File

@ -160,10 +160,17 @@ Cloudron.prototype.uninstallApp = function (appId) {
}
Cloudron.prototype.update = function (toVersion) {
var res = request.post(this._origin + '/api/v1/cloudron/update').query({ access_token: this._credentials.accessToken }).send({ password: this._credentials.password }).end();
verifyResponse(res, 'Could not update');
console.log('Update started'.green);
process.stdout.write('Trying to update');
while (true) {
sleep(10);
process.stdout.write('.');
var res = request.post(this._origin + '/api/v1/cloudron/update').query({ access_token: this._credentials.accessToken }).send({ password: this._credentials.password }).end();
if (res.statusCode === 422) continue; // box has not seen the update yet
verifyResponse(res, 'Could not update');
break;
}
console.log('Update started'.green);
process.stdout.write('Waiting for update.');
for (var i = 0; i < 40; i++) {
sleep(10);