mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-01-20 11:38:51 +00:00
Pause updates while purging or restarting apps, and ensure an applyTarget is triggered after the actions run
Signed-off-by: Pablo Carranza Velez <pablo@resin.io>
This commit is contained in:
parent
82d5a16c8c
commit
484a688dbd
@ -61,10 +61,13 @@ class ApplicationManagerRouter
|
||||
stoppedApp = _.cloneDeep(app)
|
||||
stoppedApp.services = []
|
||||
currentState.local.apps[appId] = stoppedApp
|
||||
@deviceState.applyIntermediateTarget(currentState, { skipLock: true })
|
||||
.then =>
|
||||
currentState.local.apps[appId] = app
|
||||
@deviceState.pausingApply =>
|
||||
@deviceState.applyIntermediateTarget(currentState, { skipLock: true })
|
||||
.then =>
|
||||
currentState.local.apps[appId] = app
|
||||
@deviceState.applyIntermediateTarget(currentState, { skipLock: true })
|
||||
.finally =>
|
||||
@deviceState.triggerApplyTarget()
|
||||
|
||||
doPurge = (appId, force) =>
|
||||
@logger.logSystemMessage("Purging data for app #{appId}", { appId }, 'Purge data')
|
||||
@ -76,10 +79,13 @@ class ApplicationManagerRouter
|
||||
purgedApp.services = []
|
||||
purgedApp.volumes = {}
|
||||
currentState.local.apps[appId] = purgedApp
|
||||
@deviceState.applyIntermediateTarget(currentState, { skipLock: true })
|
||||
.then =>
|
||||
currentState.local.apps[appId] = app
|
||||
@deviceState.pausingApply =>
|
||||
@deviceState.applyIntermediateTarget(currentState, { skipLock: true })
|
||||
.then =>
|
||||
currentState.local.apps[appId] = app
|
||||
@deviceState.applyIntermediateTarget(currentState, { skipLock: true })
|
||||
.finally =>
|
||||
@deviceState.triggerApplyTarget()
|
||||
.tap =>
|
||||
@logger.logSystemMessage('Purged data', { appId }, 'Purge data success')
|
||||
.catch (err) =>
|
||||
|
@ -533,12 +533,26 @@ module.exports = class DeviceState extends EventEmitter
|
||||
updateContext.applyContinueScheduled = false
|
||||
@applyTarget({ force, initial, intermediate }, updateContext)
|
||||
|
||||
pauseNextApply: =>
|
||||
@applyBlocker = new Promise (resolve) =>
|
||||
@applyUnblocker = resolve
|
||||
pausingApply: (fn) =>
|
||||
lock = =>
|
||||
@_writeLock('pause').disposer (release) ->
|
||||
release()
|
||||
pause = =>
|
||||
Promise.try =>
|
||||
res = null
|
||||
@applyBlocker = new Promise (resolve) ->
|
||||
res = resolve
|
||||
return res
|
||||
.disposer (resolve) ->
|
||||
resolve()
|
||||
|
||||
Promise.using lock(), ->
|
||||
Promise.using pause(), ->
|
||||
fn()
|
||||
|
||||
resumeNextApply: =>
|
||||
@applyUnblocker?()
|
||||
return
|
||||
|
||||
triggerApplyTarget: ({ force = false, delay = 0, initial = false } = {}) =>
|
||||
if @applyInProgress
|
||||
|
Loading…
Reference in New Issue
Block a user