handle inS3 flag

This commit is contained in:
Henrique Dias 2015-08-09 17:50:15 -03:00
parent daa42bcea0
commit 3bc5380468
3 changed files with 20 additions and 5 deletions

View file

@ -28,7 +28,9 @@ module.exports = DocArchiveManager =
else
MongoAWS.archiveDocHistory project_id, doc_id, (error) ->
logger.log doc_id:doc_id, error: error, "mongoexport"
return callback()
MongoManager.markDocHistoryAsArchived doc_id, (error) ->
return callback(error) if error?
callback()
unArchiveAllDocsChanges: (project_id, callback = (error, docs) ->) ->
MongoManager.getProjectsDocs project_id, (error, docs) ->
@ -47,4 +49,6 @@ module.exports = DocArchiveManager =
else
MongoAWS.unArchiveDocHistory project_id, doc_id, (error) ->
logger.log doc_id:doc_id, error: error, "mongoimport"
return callback()
MongoManager.markDocHistoryAsUnarchived doc_id, (error) ->
return callback(error) if error?
callback()

View file

@ -11,11 +11,13 @@ module.exports = MongoAWS =
archiveDocHistory: (project_id, doc_id, callback = (error) ->) ->
MongoAWS.mongoExportDocHistory doc_id, (error, filepath) ->
MongoAWS.s3upStream project_id, doc_id, filepath, callback
#delete temp file?
unArchiveDocHistory: (project_id, doc_id, callback = (error) ->) ->
MongoAWS.s3downStream project_id, doc_id, (error, filepath) ->
if error == null
MongoAWS.mongoImportDocHistory filepath, callback
#delete temp file?
else
callback

View file

@ -130,8 +130,17 @@ module.exports = MongoManager =
getProjectsDocs: (project_id, callback)->
db.docs.find project_id: ObjectId(project_id.toString()), {}, callback
getDocChanges: (doc_id, callback)->
db.docHistory.find doc_id: ObjectId(doc_id.toString()), {}, callback
getDocChangesCount: (doc_id, callback)->
db.docHistory.count doc_id: ObjectId(doc_id.toString()), {}, callback
markDocHistoryAsArchived: (doc_id, callback)->
MongoManager.getLastCompressedUpdate doc_id, (error, update) ->
db.docHistory.update { _id: update._id }, { $set : { inS3 : true } }, (error)->
return callback(error) if error?
db.docHistory.remove { doc_id : doc_id, inS3 : { $exists : false } }, (error)->
return callback(error) if error?
callback(error)
markDocHistoryAsUnarchived: (doc_id, callback)->
db.docHistory.update { doc_id: doc_id }, { $unset : { inS3 : true } }, { multi: true }, (error)->
callback(error)