Delete old pings also on startup
This commit is contained in:
parent
23b46a3dd5
commit
37a1579b37
12
lib/app.js
12
lib/app.js
@ -22,11 +22,13 @@ class App {
|
||||
// Setup database instance
|
||||
this.database.ensureIndexes(() => {
|
||||
this.database.loadGraphPoints(config.graphDuration, () => {
|
||||
if (config.deleteOldPings) {
|
||||
this.database.initOldPingsDeleter()
|
||||
}
|
||||
|
||||
this.database.loadRecords(callback)
|
||||
this.database.loadRecords(() => {
|
||||
if (config.deleteOldPings) {
|
||||
this.database.initOldPingsDelete(callback)
|
||||
} else {
|
||||
callback()
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
@ -267,12 +267,18 @@ class Database {
|
||||
statement.finalize()
|
||||
}
|
||||
|
||||
initOldPingsDeleter () {
|
||||
// Delete old records every hour
|
||||
setInterval(() => this.deleteOldPingRecords(), 3600000)
|
||||
initOldPingsDelete (callback) {
|
||||
// Delete old ping records on startup
|
||||
logger.info('Deleting old ping records..')
|
||||
this.deleteOldPingRecords(() => {
|
||||
// Delete old ping records every hour
|
||||
setInterval(() => this.deleteOldPingRecords(), 3600000)
|
||||
|
||||
callback()
|
||||
})
|
||||
}
|
||||
|
||||
deleteOldPingRecords () {
|
||||
deleteOldPingRecords (callback) {
|
||||
// The oldest timestamp that will be kept
|
||||
const oldestTimestamp = TimeTracker.getEpochMillis() - config.graphDuration
|
||||
|
||||
@ -285,6 +291,10 @@ class Database {
|
||||
} else {
|
||||
const deleteTook = TimeTracker.getEpochMillis() - deleteStart
|
||||
logger.info(`Old ping records deleted in ${deleteTook}ms`)
|
||||
|
||||
if (callback !== undefined) {
|
||||
callback()
|
||||
}
|
||||
}
|
||||
})
|
||||
statement.finalize()
|
||||
|
Loading…
Reference in New Issue
Block a user