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) toBeInstalled = _.difference(remoteApps, localApps)
console.log(toBeInstalled) console.log(toBeInstalled)
Promise.all(toBeRemoved.map(kill)).then(-> # Install the apps and add each to the db as they succeed
Promise.all(toBeInstalled.map(start)) promises = toBeInstalled.map (app) ->
).then(-> start(app).then ->
knex('app').whereIn('imageId', toBeRemoved).delete().then(-> knex('app').insert({imageId: app})
knex('app').insert(({imageId: app} for app in toBeInstalled)) # 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)
) )
) )