mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-01-19 11:16:34 +00:00
On update failure schedule another attempt briefly in the future.
This commit is contained in:
parent
ba5e186ebc
commit
7072b1df96
@ -143,7 +143,8 @@ exports.restart = restart = (app) ->
|
|||||||
# 1 - Updating
|
# 1 - Updating
|
||||||
# 2 - Update required
|
# 2 - Update required
|
||||||
currentlyUpdating = 0
|
currentlyUpdating = 0
|
||||||
exports.update = ->
|
failedUpdates = 0
|
||||||
|
exports.update = update = ->
|
||||||
if currentlyUpdating isnt 0
|
if currentlyUpdating isnt 0
|
||||||
# Mark an update required after the current.
|
# Mark an update required after the current.
|
||||||
currentlyUpdating = 2
|
currentlyUpdating = 2
|
||||||
@ -229,11 +230,22 @@ exports.update = ->
|
|||||||
.then ->
|
.then ->
|
||||||
knex('app').update(app).where(imageId: app.imageId)
|
knex('app').update(app).where(imageId: app.imageId)
|
||||||
Promise.all(installingPromises.concat(updatingPromises))
|
Promise.all(installingPromises.concat(updatingPromises))
|
||||||
|
.then ->
|
||||||
|
failedUpdates = 0
|
||||||
|
.catch (err) ->
|
||||||
|
failedUpdates++
|
||||||
|
if currentlyUpdating is 2
|
||||||
|
console.log('Updating failed, but there is already another update scheduled immediately: ', err)
|
||||||
|
return
|
||||||
|
delayTime = Math.min(failedUpdates * 500, 30000)
|
||||||
|
# If there was an error then schedule another attempt briefly in the future.
|
||||||
|
console.log('Scheduling another update attempt due to failure: ', delayTime, err)
|
||||||
|
setTimeout(update, delayTime)
|
||||||
.finally ->
|
.finally ->
|
||||||
updateDeviceInfo(status: 'Idle')
|
updateDeviceInfo(status: 'Idle')
|
||||||
if currentlyUpdating is 2
|
if currentlyUpdating is 2
|
||||||
# If an update is required then schedule it
|
# If an update is required then schedule it
|
||||||
setTimeout(exports.update)
|
setTimeout(update)
|
||||||
# Set the updating as finished
|
# Set the updating as finished
|
||||||
currentlyUpdating = 0
|
currentlyUpdating = 0
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user