diff --git a/services/track-changes/app/coffee/DocArchiveManager.coffee b/services/track-changes/app/coffee/DocArchiveManager.coffee index 1ae3b22363..05d8430984 100644 --- a/services/track-changes/app/coffee/DocArchiveManager.coffee +++ b/services/track-changes/app/coffee/DocArchiveManager.coffee @@ -38,12 +38,18 @@ module.exports = DocArchiveManager = else MongoManager.getLastCompressedUpdate doc_id, (error, update) -> return callback(error) if error? - MongoAWS.archiveDocHistory project_id, doc_id, (error) -> + MongoManager.markDocHistoryAsArchiveInProgress doc_id, update, (error) -> return callback(error) if error? - 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() + 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) -> diff --git a/services/track-changes/app/coffee/MongoManager.coffee b/services/track-changes/app/coffee/MongoManager.coffee index 78627ebbd3..c31d466655 100644 --- a/services/track-changes/app/coffee/MongoManager.coffee +++ b/services/track-changes/app/coffee/MongoManager.coffee @@ -146,6 +146,12 @@ module.exports = MongoManager = getArchivedDocChanges: (doc_id, callback)-> db.docHistory.count { doc_id: ObjectId(doc_id.toString()) , inS3: true }, {}, callback + markDocHistoryAsArchiveInProgress: (doc_id, update, callback) -> + db.docHistory.update { _id: update._id }, { $set : { inS3 : false } }, callback + + clearDocHistoryAsArchiveInProgress: (doc_id, update, callback) -> + db.docHistory.update { _id: update._id }, { $set : { inS3 : false } }, callback + markDocHistoryAsArchived: (doc_id, update, callback)-> db.docHistory.update { _id: update._id }, { $set : { inS3 : true } }, (error)-> return callback(error) if error? @@ -154,5 +160,6 @@ module.exports = MongoManager = callback(error) markDocHistoryAsUnarchived: (doc_id, callback)-> + # note this removes any inS3 field, regardless of its value (true/false/null) db.docHistory.update { doc_id: ObjectId(doc_id.toString()) }, { $unset : { inS3 : true } }, { multi: true }, (error)-> callback(error) diff --git a/services/track-changes/app/coffee/UpdatesManager.coffee b/services/track-changes/app/coffee/UpdatesManager.coffee index 0eb69b2b23..68507d7237 100644 --- a/services/track-changes/app/coffee/UpdatesManager.coffee +++ b/services/track-changes/app/coffee/UpdatesManager.coffee @@ -103,7 +103,7 @@ module.exports = UpdatesManager = MongoManager.getProjectUpdates project_id, options, (error, updates) -> jobs = [] for update in updates - if update.inS3? + if update.inS3 do (update) -> jobs.push (callback) -> DocArchiveManager.unArchiveDocChanges update.project_id, update.doc_id, callback if jobs.length?