2019-05-10 11:10:00 +00:00
|
|
|
'use strict'
|
|
|
|
|
2020-01-04 22:14:03 +00:00
|
|
|
const models = require('../models')
|
|
|
|
const logger = require('../logger')
|
2019-05-10 11:10:00 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* clean when user not in any rooms or user not in connected list
|
|
|
|
*/
|
|
|
|
class SaveRevisionJob {
|
|
|
|
constructor (realtime) {
|
|
|
|
this.realtime = realtime
|
|
|
|
this.saverSleep = false
|
|
|
|
}
|
|
|
|
|
|
|
|
start () {
|
|
|
|
if (this.timer) return
|
|
|
|
this.timer = setInterval(this.saveRevision.bind(this), 5 * 60 * 1000)
|
|
|
|
}
|
|
|
|
|
|
|
|
stop () {
|
|
|
|
if (!this.timer) return
|
|
|
|
clearInterval(this.timer)
|
|
|
|
this.timer = undefined
|
|
|
|
}
|
|
|
|
|
|
|
|
saveRevision () {
|
|
|
|
if (this.getSaverSleep()) return
|
|
|
|
models.Revision.saveAllNotesRevision((err, notes) => {
|
|
|
|
if (err) return logger.error('revision saver failed: ' + err)
|
|
|
|
if (notes && notes.length <= 0) {
|
|
|
|
this.setSaverSleep(true)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
getSaverSleep () {
|
|
|
|
return this.saverSleep
|
|
|
|
}
|
|
|
|
|
|
|
|
setSaverSleep (val) {
|
|
|
|
this.saverSleep = val
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.SaveRevisionJob = SaveRevisionJob
|