From fc62abfcfafb0f16d8250708457cdb02e4126f18 Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Thu, 26 Sep 2019 15:46:14 +0100 Subject: [PATCH] run flush of queued projects in the background --- .../app/coffee/DeleteQueueManager.coffee | 6 +++--- .../document-updater/app/coffee/HttpController.coffee | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/services/document-updater/app/coffee/DeleteQueueManager.coffee b/services/document-updater/app/coffee/DeleteQueueManager.coffee index db69fa4b2f..568d71bcdc 100644 --- a/services/document-updater/app/coffee/DeleteQueueManager.coffee +++ b/services/document-updater/app/coffee/DeleteQueueManager.coffee @@ -46,13 +46,13 @@ module.exports = DeleteQueueManager = now = Date.now() if now - startTime > options.timeout logger.log "hit time limit on flushing old projects" - return callback() + return callback(null, count) if count > options.limit logger.log "hit count limit on flushing old projects" - return callback() + return callback(null, count) RedisManager.getNextProjectToFlushAndDelete cutoffTime, (err, project_id, flushTimestamp, queueLength) -> return callback(err) if err? - return callback() if !project_id? + return callback(null, count) if !project_id? logger.log {project_id, queueLength: queueLength}, "flushing queued project" metrics.globalGauge "queued-flush-backlog", queueLength flushProjectIfNotModified project_id, flushTimestamp, (err, flushed) -> diff --git a/services/document-updater/app/coffee/HttpController.coffee b/services/document-updater/app/coffee/HttpController.coffee index 96595c3449..537dbd4903 100644 --- a/services/document-updater/app/coffee/HttpController.coffee +++ b/services/document-updater/app/coffee/HttpController.coffee @@ -216,15 +216,15 @@ module.exports = HttpController = res.send project_ids flushQueuedProjects: (req, res, next = (error) ->) -> - res.setTimeout(5 * 60 * 1000) options = limit : req.query.limit || 1000 timeout: 5 * 60 * 1000 dryRun : req.query.dryRun || false min_delete_age: req.query.min_delete_age || 5 * 60 * 1000 - DeleteQueueManager.flushAndDeleteOldProjects options, (err, project_ids)-> + res.send 204 + # run the flush in the background + DeleteQueueManager.flushAndDeleteOldProjects options, (err, flushed)-> if err? logger.err err:err, "error flushing old projects" - res.send 500 - else - res.send project_ids + else + logger.log {flushed: flushed}, "flush of queued projects completed"