prevent double archiving by checking if any inS3 field is already present

This commit is contained in:
Brian Gough 2015-09-23 13:29:32 +01:00
parent e49f260507
commit 847a553344
2 changed files with 18 additions and 13 deletions

View file

@ -36,20 +36,25 @@ module.exports = DocArchiveManager =
logger.log {project_id, doc_id}, "document history is empty, not archiving"
return callback()
else
MongoManager.getLastCompressedUpdate doc_id, (error, update) ->
MongoManager.getArchivedDocChanges doc_id, (error, count) ->
return callback(error) if error?
MongoManager.markDocHistoryAsArchiveInProgress doc_id, update, (error) ->
if count != 0
logger.log {project_id, doc_id}, "document history contains archived entries, not archiving"
return callback()
MongoManager.getLastCompressedUpdate doc_id, (error, update) ->
return callback(error) if error?
MongoAWS.archiveDocHistory project_id, doc_id, (error) ->
if error?
MongoManager.clearDocHistoryAsArchiveInProgress doc_id, update, (err) ->
return callback(err) if err?
callback(error)
else
logger.log doc_id:doc_id, project_id:project_id, "exported document to S3"
MongoManager.markDocHistoryAsArchived doc_id, update, (error) ->
return callback(error) if error?
callback()
MongoManager.markDocHistoryAsArchiveInProgress doc_id, update, (error) ->
return callback(error) if error?
MongoAWS.archiveDocHistory project_id, doc_id, (error) ->
if error?
MongoManager.clearDocHistoryAsArchiveInProgress doc_id, update, (err) ->
return callback(err) if err?
callback(error)
else
logger.log doc_id:doc_id, project_id:project_id, "exported document to S3"
MongoManager.markDocHistoryAsArchived doc_id, update, (error) ->
return callback(error) if error?
callback()
unArchiveAllDocsChanges: (project_id, callback = (error, docs) ->) ->
DocstoreHandler.getAllDocs project_id, (error, docs) ->

View file

@ -144,7 +144,7 @@ module.exports = MongoManager =
db.docHistory.count { doc_id : ObjectId(doc_id.toString()), inS3 : { $exists : false }}, {}, callback
getArchivedDocChanges: (doc_id, callback)->
db.docHistory.count { doc_id: ObjectId(doc_id.toString()) , inS3: true }, {}, callback
db.docHistory.count { doc_id: ObjectId(doc_id.toString()) , inS3: { $exists: true }}, {}, callback
markDocHistoryAsArchiveInProgress: (doc_id, update, callback) ->
db.docHistory.update { _id: update._id }, { $set : { inS3 : false } }, callback