add metric for queue length

This commit is contained in:
Brian Gough 2019-09-25 17:04:36 +01:00
parent f6b2ac7360
commit 83dd43b809
2 changed files with 7 additions and 3 deletions

View file

@ -35,9 +35,11 @@ module.exports = DeleteQueueManager =
logger.log "hit count limit on flushing old projects"
return callback()
cutoffTime = now - options.min_delete_age
RedisManager.getNextProjectToFlushAndDelete cutoffTime, (err, project_id, flushTimestamp) ->
RedisManager.getNextProjectToFlushAndDelete cutoffTime, (err, project_id, flushTimestamp, queueLength) ->
return callback(err) if err?
return callback() if !project_id?
logger.log {project_id, queueLength: queueLength}, "flushing queued project"
metrics.globalGauge "queued-flush-backlog", queueLength
flushProjectIfNotModified project_id, flushTimestamp, (err, flushed) ->
count++ if flushed
flushNextProject()

View file

@ -298,18 +298,20 @@ module.exports = RedisManager =
rclient.zadd keys.flushAndDeleteQueue(), Date.now(), project_id, callback
getNextProjectToFlushAndDelete: (cutoffTime, callback = (error, key, timestamp)->) ->
# find the oldest queued flsus
# find the oldest queued flush
rclient.zrangebyscore keys.flushAndDeleteQueue(), 0, cutoffTime, "WITHSCORES", "LIMIT", 0, 1, (err, reply) ->
return callback(err) if err?
return callback() if !reply?.length
multi = rclient.multi()
multi.zrange keys.flushAndDeleteQueue(), 0, 0, "WITHSCORES"
multi.zremrangebyrank keys.flushAndDeleteQueue(), 0, 0
multi.zcard keys.flushAndDeleteQueue()
multi.exec (err, reply) ->
return callback(err) if err?
return callback() if !reply?.length
[key, timestamp] = reply[0]
callback(null, key, timestamp)
queueLength = reply[2]
callback(null, key, timestamp, queueLength)
_serializeRanges: (ranges, callback = (error, serializedRanges) ->) ->
jsonRanges = JSON.stringify(ranges)