mirror of
https://github.com/status-im/codimd.git
synced 2025-01-13 05:04:06 +00:00
ts: lib/realtime/realtimeSaveRevisionJob.js
Signed-off-by: Raccoon <raccoon@hackmd.io>
This commit is contained in:
parent
0f8b126d04
commit
b38915da20
@ -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
|
Loading…
x
Reference in New Issue
Block a user