diff --git a/cloudron.js b/cloudron.js index de552b1..5c76544 100644 --- a/cloudron.js +++ b/cloudron.js @@ -251,8 +251,14 @@ Cloudron.prototype.update = function (toVersion) { } console.log('Update started'.green); + + this.waitForUpdate(toVersion); +}; + +Cloudron.prototype.waitForUpdate = function (toVersion) { process.stdout.write('Waiting for update.'); - for (i = 0; i < 60; i++) { + var res; + for (var i = 0; i < 60; i++) { sleep(20); res = request.get(this._origin + '/api/v1/cloudron/status').end(); if (res.statusCode === 200 && res.body.version === toVersion) { @@ -327,6 +333,14 @@ Cloudron.prototype.checkTimeZone = function (tz) { if (tz !== res.body.timeZone) throw new Error('timezone does not match. expecting: ' + tz + ' got ' + res.body.timeZone); }; +Cloudron.prototype.setAutoupdatePattern = function (pattern) { + var res = request.post(this._origin + '/api/v1/settings/autoupdate_pattern') + .query({ access_token: this._credentials.accessToken }) + .send({ pattern: pattern }) + .end(); + common.verifyResponse2xx(res, 'Could not set autoupdate pattern'); +}; + Cloudron.prototype.checkA = function (callback) { var that = this; dns.resolve4(this._box.domain, function (error, records) { diff --git a/test/cloudron-update-sfo1-test.js b/test/cloudron-update-sfo1-test.js index 9ee337b..e0d65f9 100644 --- a/test/cloudron-update-sfo1-test.js +++ b/test/cloudron-update-sfo1-test.js @@ -107,10 +107,14 @@ describe('Cloudron update testing', function () { cloudron.checkAddons(cloudron.appFqdn(location), owner); }); + it('can set the autoupdate pattern', function () { + cloudron.setAutoupdatePattern('00 */1 * * * *'); // every minute + }); + it('can update to new version', function () { console.log('Wait for cloudron to get the update'); - sleep(60 * 2); - cloudron.update(nextVersion); + sleep(60 * 5); // give it 5 mins to autoupdate the box and the app + cloudron.waitForUpdate(nextVersion); }); it('runs the app', function () {