Merge pull request #966 from balena-io/fix-db-cleanup-code

fix: Run db log cleanup on init - after migrations
This commit is contained in:
CameronDiver 2019-04-25 17:25:57 +01:00 committed by GitHub
commit fe477d65a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -75,19 +75,6 @@ module.exports = class ApplicationManager extends EventEmitter
@_targetVolatilePerImageId = {}
@_containerStarted = {}
# Rather than relying on removing out of data database entries when we're no
# longer using them, set a task that runs periodically to clear out the database
# This has the advantage that if for some reason a container is removed while the
# supervisor is down, we won't have zombie entries in the db
setInterval =>
@docker.listContainers(all: true).then (containers) =>
@logger.clearOutOfDateDBLogs(_.map(containers, 'Id'))
# Once a day
, 1000 * 60 * 60 * 24
# But also run it in the background on startup
@docker.listContainers(all: true).then (containers) =>
@logger.clearOutOfDateDBLogs(_.map(containers, 'Id'))
@config.on 'change', (changedConfig) =>
if changedConfig.appUpdatePollInterval
@images.appUpdatePollInterval = changedConfig.appUpdatePollInterval
@ -201,6 +188,20 @@ module.exports = class ApplicationManager extends EventEmitter
@images.appUpdatePollInterval = interval
@images.cleanupDatabase()
.then =>
cleanup = =>
@docker.listContainers(all: true).then (containers) =>
@logger.clearOutOfDateDBLogs(_.map(containers, 'Id'))
# Rather than relying on removing out of date database entries when we're no
# longer using them, set a task that runs periodically to clear out the database
# This has the advantage that if for some reason a container is removed while the
# supervisor is down, we won't have zombie entries in the db
# Once a day
setInterval(cleanup, 1000 * 60 * 60 * 24)
# But also run it in on startup
cleanup()
.then =>
@localModeManager.init()
.then =>
@services.attachToRunning()