Install apps in parallel to deleting them - also fixes SQL errors when there are no apps to install.

This commit is contained in:
Page 2014-03-14 16:52:05 +00:00 committed by Pablo Carranza Vélez
parent aad38a487f
commit 3c3e81a892

View File

@ -109,13 +109,16 @@ exports.update = ->
toBeInstalled = _.difference(remoteApps, localApps)
console.log(toBeInstalled)
Promise.all(toBeRemoved.map(kill)).then(->
Promise.all(toBeInstalled.map(start))
).then(->
knex('app').whereIn('imageId', toBeRemoved).delete().then(->
knex('app').insert(({imageId: app} for app in toBeInstalled))
)
# Install the apps and add each to the db as they succeed
promises = toBeInstalled.map (app) ->
start(app).then ->
knex('app').insert({imageId: app})
# And delete all the ones to remove in one go
promises.push(
Promise.all(toBeRemoved.map(kill)).then ->
knex('app').whereIn('imageId', toBeRemoved).delete()
)
Promise.all(promises)
)
)