mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-23 17:19:37 +02:00
Merge pull request #29321 from overleaf/bg-ignore-deleted-projects-in-history-backup
handle deleted projects in history-v1 backup worker GitOrigin-RevId: f4392045074248137f15d082d922c18b1ef9232f
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
const { Binary, ObjectId } = require('mongodb')
|
||||
const { projects, backedUpBlobs } = require('../mongodb')
|
||||
const { projects, deletedProjects, backedUpBlobs } = require('../mongodb')
|
||||
const OError = require('@overleaf/o-error')
|
||||
|
||||
// List projects with pending backups older than the specified interval
|
||||
@@ -79,6 +79,13 @@ async function getBackupStatus(projectId) {
|
||||
}
|
||||
)
|
||||
if (!project) {
|
||||
// Check whether the project was deleted
|
||||
const deletedProject = await deletedProjects.findOne({
|
||||
'deleterData.deletedProjectId': new ObjectId(projectId),
|
||||
})
|
||||
if (deletedProject) {
|
||||
throw new Error('Project deleted')
|
||||
}
|
||||
throw new Error('Project not found')
|
||||
}
|
||||
return {
|
||||
|
||||
@@ -14,6 +14,7 @@ const blobs = db.collection('projectHistoryBlobs')
|
||||
const globalBlobs = db.collection('projectHistoryGlobalBlobs')
|
||||
const shardedBlobs = db.collection('projectHistoryShardedBlobs')
|
||||
const projects = db.collection('projects')
|
||||
const deletedProjects = db.collection('deletedProjects')
|
||||
// Temporary collection for tracking progress of backed up old blobs (without a hash).
|
||||
// The initial sync process will be able to skip over these.
|
||||
// Schema: _id: projectId, blobs: [Binary]
|
||||
@@ -32,6 +33,7 @@ module.exports = {
|
||||
blobs,
|
||||
globalBlobs,
|
||||
projects,
|
||||
deletedProjects,
|
||||
shardedBlobs,
|
||||
backedUpBlobs,
|
||||
cleanupTestDatabase,
|
||||
|
||||
@@ -114,9 +114,14 @@ async function runBackup(projectId, data, job) {
|
||||
}
|
||||
return `backup completed ${projectId}`
|
||||
} catch (err) {
|
||||
metrics.inc('backup_worker_project', 1, { status: 'failed' })
|
||||
logger.error({ projectId, err }, 'backup failed')
|
||||
throw err // Re-throw to mark job as failed
|
||||
if (err.message === 'Project deleted') {
|
||||
metrics.inc('backup_worker_project', 1, { status: 'deleted' })
|
||||
logger.warn({ projectId, err }, 'skipping backup of deleted project')
|
||||
} else {
|
||||
metrics.inc('backup_worker_project', 1, { status: 'failed' })
|
||||
logger.error({ projectId, err }, 'backup failed')
|
||||
throw err // Re-throw to mark job as failed
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user