From 976f19f763a297c6bac083c31036973317b138c3 Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Thu, 20 Apr 2017 10:14:44 +0100 Subject: [PATCH 1/3] remove spurious call to getAllDocIdsWithHistoryOps --- services/track-changes/app/coffee/UpdatesManager.coffee | 1 - 1 file changed, 1 deletion(-) diff --git a/services/track-changes/app/coffee/UpdatesManager.coffee b/services/track-changes/app/coffee/UpdatesManager.coffee index ca79d26d59..3c12b2a713 100644 --- a/services/track-changes/app/coffee/UpdatesManager.coffee +++ b/services/track-changes/app/coffee/UpdatesManager.coffee @@ -159,7 +159,6 @@ module.exports = UpdatesManager = return callback(error) if error? failedProjects = (x.project_id for x in result when x.failed) succeededProjects = (x.project_id for x in result when not x.failed) - RedisManager.getAllDocIdsWithHistoryOps (error, doc_ids) -> callback(null, {failed: failedProjects, succeeded: succeededProjects}) getDanglingUpdates: (callback = (error, doc_ids) ->) -> From 43f51355b26d69be2cafc1fa14e06e08e3e84d4d Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Thu, 20 Apr 2017 11:01:46 +0100 Subject: [PATCH 2/3] add limit parameter to flushAll --- .../track-changes/app/coffee/HttpController.coffee | 12 ++++++++---- .../track-changes/app/coffee/UpdatesManager.coffee | 7 ++++--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/services/track-changes/app/coffee/HttpController.coffee b/services/track-changes/app/coffee/HttpController.coffee index 0b59a6e1ec..4f99cdfda3 100644 --- a/services/track-changes/app/coffee/HttpController.coffee +++ b/services/track-changes/app/coffee/HttpController.coffee @@ -23,12 +23,16 @@ module.exports = HttpController = res.send 204 flushAll: (req, res, next = (error) ->) -> - logger.log "flushing all projects" - UpdatesManager.flushAll (error, result) -> + # limit on projects to flush or -1 for all (default) + limit = if req.query.limit? then parseInt(req.query.limit, 10) else -1 + logger.log {limit: limit}, "flushing all projects" + UpdatesManager.flushAll limit, (error, result) -> return next(error) if error? - {failed, succeeded} = result + {failed, succeeded, all} = result status = "#{succeeded.length} succeeded, #{failed.length} failed" - if failed.length > 0 + if limit == 0 + res.status(200).send "#{status}\nwould flush:\n#{all.join('\n')}\n" + else if failed.length > 0 logger.log {failed: failed, succeeded: succeeded}, "error flushing projects" res.status(500).send "#{status}\nfailed to flush:\n#{failed.join('\n')}\n" else diff --git a/services/track-changes/app/coffee/UpdatesManager.coffee b/services/track-changes/app/coffee/UpdatesManager.coffee index 3c12b2a713..f3571dc16d 100644 --- a/services/track-changes/app/coffee/UpdatesManager.coffee +++ b/services/track-changes/app/coffee/UpdatesManager.coffee @@ -145,12 +145,13 @@ module.exports = UpdatesManager = async.parallelLimit jobs, 5, callback # flush all outstanding changes - flushAll: (callback = (error, result) ->) -> + flushAll: (limit, callback = (error, result) ->) -> RedisManager.getProjectIdsWithHistoryOps (error, project_ids) -> return callback(error) if error? logger.log {count: project_ids?.length, project_ids: project_ids}, "found projects" jobs = [] - for project_id in project_ids + selectedProjects = if limit < 0 then project_ids else project_ids[0...limit] + for project_id in selectedProjects do (project_id) -> jobs.push (cb) -> UpdatesManager.processUncompressedUpdatesForProject project_id, (err) -> @@ -159,7 +160,7 @@ module.exports = UpdatesManager = return callback(error) if error? failedProjects = (x.project_id for x in result when x.failed) succeededProjects = (x.project_id for x in result when not x.failed) - callback(null, {failed: failedProjects, succeeded: succeededProjects}) + callback(null, {failed: failedProjects, succeeded: succeededProjects, all: project_ids}) getDanglingUpdates: (callback = (error, doc_ids) ->) -> RedisManager.getAllDocIdsWithHistoryOps (error, all_doc_ids) -> From 9eb36f9692b05d672c4a4d9db4747239e8abf463 Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Thu, 20 Apr 2017 11:55:32 +0100 Subject: [PATCH 3/3] improve log message for flushing --- services/track-changes/app/coffee/HttpController.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/track-changes/app/coffee/HttpController.coffee b/services/track-changes/app/coffee/HttpController.coffee index 4f99cdfda3..9ede86f3ee 100644 --- a/services/track-changes/app/coffee/HttpController.coffee +++ b/services/track-changes/app/coffee/HttpController.coffee @@ -36,7 +36,7 @@ module.exports = HttpController = logger.log {failed: failed, succeeded: succeeded}, "error flushing projects" res.status(500).send "#{status}\nfailed to flush:\n#{failed.join('\n')}\n" else - res.status(200).send "#{status}\nflushed all #{succeeded.length} projects\n" + res.status(200).send "#{status}\nflushed #{succeeded.length} projects of #{all.length}\n" checkDanglingUpdates: (req, res, next = (error) ->) -> logger.log "checking dangling updates"