In /v1/update, return 202 when we're not updating immediately

We also add a catch to any errors when getting configuration, and send 503 in this case, even if it's
unlikely.

Change-type: patch
Signed-off-by: Pablo Carranza Velez <pablo@balena.io>
This commit is contained in:
Pablo Carranza Velez 2019-03-29 14:29:00 -07:00
parent 8f07bf62de
commit 9961ebb41d

View File

@ -920,17 +920,33 @@ export class APIBinder {
router.post('/v1/update', (req, res) => {
apiBinder.eventTracker.track('Update notification');
if (apiBinder.readyForUpdates) {
this.config.get('instantUpdates').then(instantUpdates => {
if (instantUpdates) {
apiBinder.getAndSetTargetState(req.body.force, true).catch(_.noop);
} else {
console.log(
'Ignoring update notification because instant updates are disabled',
);
}
});
this.config
.get('instantUpdates')
.then(instantUpdates => {
if (instantUpdates) {
apiBinder
.getAndSetTargetState(req.body.force, true)
.catch(_.noop);
res.sendStatus(204);
} else {
console.log(
'Ignoring update notification because instant updates are disabled',
);
res.sendStatus(202);
}
})
.catch(err => {
const msg =
err.message != null
? err.message
: err != null
? err
: 'Unknown error';
res.status(503).send(msg);
});
} else {
res.sendStatus(202);
}
res.sendStatus(204);
});
return router;