run flush of queued projects in the background

This commit is contained in:
Brian Gough 2019-09-26 15:46:14 +01:00
parent ba35c73cb6
commit fc62abfcfa
2 changed files with 8 additions and 8 deletions

View file

@ -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) ->

View file

@ -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"