Просмотр исходного кода

add dryRun option to flush all projects

Henry Oswald 7 лет назад
Родитель
Сommit
daca83a057

+ 5 - 3
services/document-updater/app/coffee/HttpController.coffee

@@ -184,9 +184,11 @@ module.exports = HttpController =
 
 
 	flushAllProjects: (req, res, next = (error)-> )->
 	flushAllProjects: (req, res, next = (error)-> )->
 		res.setTimeout(5 * 60 * 1000)
 		res.setTimeout(5 * 60 * 1000)
-		limit = req.query.limit || 1000
-		concurrency = req.query.concurrency || 5
-		ProjectFlusher.flushAllProjects limit, concurrency, (err, project_ids)->
+		options = 
+			limit : req.query.limit || 1000
+			concurrency : req.query.concurrency || 5
+			dryRun : req.query.dryRun || false
+		ProjectFlusher.flushAllProjects options, (err, project_ids)->
 			if err?
 			if err?
 				logger.err err:err, "error bulk flushing projects"
 				logger.err err:err, "error bulk flushing projects"
 				res.send 500
 				res.send 500

+ 5 - 3
services/document-updater/app/coffee/ProjectFlusher.coffee

@@ -45,16 +45,18 @@ ProjectFlusher =
 			m[1]
 			m[1]
 		return ids
 		return ids
 
 
-	flushAllProjects: (limit, concurrency = 5, callback)->
-		ProjectFlusher._getKeys docUpdaterKeys.docsInProject({project_id:"*"}), limit, (error, project_keys) ->
+	flushAllProjects: (options, callback)->
+		ProjectFlusher._getKeys docUpdaterKeys.docsInProject({project_id:"*"}), options.limit, (error, project_keys) ->
 			if error?
 			if error?
 				logger.err err:error, "error getting keys for flushing"
 				logger.err err:error, "error getting keys for flushing"
 				return callback(error)
 				return callback(error)
 			project_ids = ProjectFlusher._extractIds(project_keys)
 			project_ids = ProjectFlusher._extractIds(project_keys)
+			if options.dryRun
+				return callback(null, project_ids)
 			jobs = _.map project_ids, (project_id)->
 			jobs = _.map project_ids, (project_id)->
 				return (cb)->
 				return (cb)->
 					ProjectManager.flushAndDeleteProjectWithLocks project_id, cb
 					ProjectManager.flushAndDeleteProjectWithLocks project_id, cb
-			async.parallelLimit jobs, concurrency, (error)->
+			async.parallelLimit jobs, options.concurrency, (error)->
 				return callback(error, project_ids)
 				return callback(error, project_ids)