ts: lib/realtime/realtimeSaveRevisionJob.js

Signed-off-by: Raccoon <raccoon@hackmd.io>
This commit is contained in:
Raccoon 2021-06-12 06:32:19 +08:00
parent 0f8b126d04
commit b38915da20
No known key found for this signature in database
GPG Key ID: 06770355DC9ECD38

View File

@ -1,29 +1,33 @@
'use strict'
const models = require('../models')
const logger = require('../logger')
import * as models from "../models";
import * as logger from "../logger";
/**
* clean when user not in any rooms or user not in connected list
*/
class SaveRevisionJob {
constructor (realtime) {
export class SaveRevisionJob {
private realtime: any;
private saverSleep: boolean;
private timer: NodeJS.Timeout;
constructor(realtime) {
this.realtime = realtime
this.saverSleep = false
}
start () {
start() {
if (this.timer) return
this.timer = setInterval(this.saveRevision.bind(this), 5 * 60 * 1000)
}
stop () {
stop() {
if (!this.timer) return
clearInterval(this.timer)
this.timer = undefined
}
saveRevision () {
saveRevision() {
if (this.getSaverSleep()) return
models.Revision.saveAllNotesRevision((err, notes) => {
if (err) return logger.error('revision saver failed: ' + err)
@ -33,13 +37,11 @@ class SaveRevisionJob {
})
}
getSaverSleep () {
getSaverSleep() {
return this.saverSleep
}
setSaverSleep (val) {
setSaverSleep(val) {
this.saverSleep = val
}
}
exports.SaveRevisionJob = SaveRevisionJob