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:
Page 2014-05-01 19:43:44 +01:00 committed by Pablo Carranza Vélez
parent 9c9288e179
commit 06ef69f87e

View File

@ -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