mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 06:03:45 +01:00
Add functions for monitoring backup status of db records
GitOrigin-RevId: f0d3564dfd3b38ef9ee451de866c0c05acd0cb20
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import Metrics from '@overleaf/metrics'
|
||||
import { objectIdFromDate } from './utils.mjs'
|
||||
import { db } from '../storage/lib/mongodb.js'
|
||||
|
||||
const projectsCollection = db.collection('projects')
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Date} beforeTime
|
||||
* @return {Promise<void>}
|
||||
*/
|
||||
export async function measurePendingChangesBeforeTime(beforeTime) {
|
||||
const pendingChangeCount = await projectsCollection.countDocuments({
|
||||
'overleaf.backup.pendingChangeAt': {
|
||||
$lt: beforeTime,
|
||||
},
|
||||
})
|
||||
|
||||
Metrics.gauge('backup_verification_pending_changes', pendingChangeCount)
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {number} graceSeconds - Number of seconds projects are allowed before they must be backed up.
|
||||
* @return {Promise<void>}
|
||||
*/
|
||||
export async function measureNeverBackedUpProjects(graceSeconds) {
|
||||
const now = new Date()
|
||||
const startOfGracePeriod = new Date(now - graceSeconds * 1000)
|
||||
const neverBackedUpCount = await projectsCollection.countDocuments({
|
||||
'overleaf.backup.lastBackedUpVersion': null,
|
||||
_id: { $lt: objectIdFromDate(startOfGracePeriod) },
|
||||
})
|
||||
Metrics.gauge('backup_verification_never_backed_up', neverBackedUpCount)
|
||||
}
|
||||
Reference in New Issue
Block a user