Archive changes, care about: versioin, expiresAt and Lock

This commit is contained in:
Henrique Dias 2015-08-14 15:07:16 -03:00
parent 6bc9c9010a
commit fd4afb3574
3 changed files with 21 additions and 13 deletions

View file

@ -1,5 +1,6 @@
MongoManager = require "./MongoManager"
MongoAWS = require "./MongoAWS"
LockManager = require "./LockManager"
logger = require "logger-sharelatex"
_ = require "underscore"
async = require "async"
@ -19,20 +20,28 @@ module.exports = DocArchiveManager =
else if !docs?
return callback new Error("No docs for project #{project_id}")
jobs = _.map docs, (doc) ->
(cb)-> DocArchiveManager.archiveDocChanges project_id, doc._id, cb
(cb)-> DocArchiveManager.archiveDocChangesWithLock project_id, doc._id, cb
async.series jobs, callback
archiveDocChangesWithLock: (project_id, doc_id, callback = (error) ->) ->
LockManager.runWithLock(
"HistoryArchiveLock:#{doc_id}",
(releaseLock) ->
DocArchiveManager.archiveDocChanges project_id, doc_id, releaseLock
callback
)
archiveDocChanges: (project_id, doc_id, callback)->
MongoManager.getDocChangesCount doc_id, (error, count) ->
if count == 0
return callback()
else
MongoAWS.archiveDocHistory project_id, doc_id, (error) ->
logger.log doc_id:doc_id, error: error, "mongoexport"
MongoManager.markDocHistoryAsArchived doc_id, (error) ->
return callback(error) if error?
callback()
MongoManager.getLastCompressedUpdate doc_id, (error, update) ->
MongoAWS.archiveDocHistory project_id, doc_id, (error) ->
logger.log doc_id:doc_id, error: error, "mongoexport"
MongoManager.markDocHistoryAsArchived doc_id, update, (error) ->
return callback(error) if error?
callback()
unArchiveAllDocsChanges: (project_id, callback = (error, docs) ->) ->
if settings.filestore?.backend != "s3"

View file

@ -33,7 +33,7 @@ module.exports = MongoAWS =
args.push '-c'
args.push 'docHistory'
args.push '-q'
args.push "{doc_id: ObjectId('#{doc_id}') }"
args.push "{doc_id: ObjectId('#{doc_id}') , expiresAt: {$exists : false} }"
args.push '-o'
args.push filepath

View file

@ -140,13 +140,12 @@ module.exports = MongoManager =
getArchivedDocChanges: (doc_id, callback)->
db.docHistory.count { doc_id: ObjectId(doc_id.toString()) , inS3: true }, {}, callback
markDocHistoryAsArchived: (doc_id, callback)->
MongoManager.getLastCompressedUpdate doc_id, (error, update) ->
db.docHistory.update { _id: update._id }, { $set : { inS3 : true } }, (error)->
markDocHistoryAsArchived: (doc_id, update, callback)->
db.docHistory.update { v: update.v }, { $set : { inS3 : true } }, (error)->
return callback(error) if error?
db.docHistory.remove { doc_id : doc_id, inS3 : { $exists : false }, v: { $lt : update.v }, expiresAt: {$exists : false} }, (error)->
return callback(error) if error?
db.docHistory.remove { doc_id : doc_id, inS3 : { $exists : false } }, (error)->
return callback(error) if error?
callback(error)
callback(error)
markDocHistoryAsUnarchived: (doc_id, callback)->
db.docHistory.update { doc_id: doc_id }, { $unset : { inS3 : true } }, { multi: true }, (error)->