From 6b7f9e5b9af0ca564d55c049386c77d89f50b259 Mon Sep 17 00:00:00 2001 From: Girish Ramakrishnan Date: Thu, 16 Jul 2015 15:05:06 -0700 Subject: [PATCH] Loop until box receives an update --- cloudron.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/cloudron.js b/cloudron.js index 3b07939..36d2d55 100644 --- a/cloudron.js +++ b/cloudron.js @@ -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);