mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2024-12-20 06:07:57 +00:00
Only allow one update to be occurring at a time, and if another is triggered whilst one is in progress then simply schedule it for after the current one finishes.
This commit is contained in:
parent
9c9288e179
commit
06ef69f87e
@ -87,7 +87,16 @@ exports.restart = restart = (app) ->
|
||||
.then ->
|
||||
start(app)
|
||||
|
||||
# 0 - Idle
|
||||
# 1 - Updating
|
||||
# 2 - Update required
|
||||
currentlyUpdating = 0
|
||||
exports.update = ->
|
||||
if currentlyUpdating isnt 0
|
||||
# Mark an update required after the current.
|
||||
currentlyUpdating = 2
|
||||
return
|
||||
currentlyUpdating = 1
|
||||
Promise.all([
|
||||
knex('config').select('value').where(key: 'apiKey')
|
||||
knex('config').select('value').where(key: 'uuid')
|
||||
@ -161,3 +170,9 @@ exports.update = ->
|
||||
knex('app').whereIn('imageId', toBeRemoved).delete()
|
||||
)
|
||||
Promise.all(promises)
|
||||
.finally ->
|
||||
if currentlyUpdating is 2
|
||||
# If an update is required then schedule it
|
||||
setTimeout(exports.update)
|
||||
# Set the updating as finished
|
||||
currentlyUpdating = 0
|
||||
|
Loading…
Reference in New Issue
Block a user