use time-based cleaning of event log

This commit is contained in:
Brian Gough 2019-03-21 14:48:51 +00:00
parent befe4be517
commit 9b25374cd3

View file

@ -5,11 +5,10 @@ logger = require 'logger-sharelatex'
EVENT_LOG_COUNTER = {} EVENT_LOG_COUNTER = {}
EVENT_LOG_TIMESTAMP = {} EVENT_LOG_TIMESTAMP = {}
EVENT_COUNT = 0 EVENT_LAST_CLEAN_TIMESTAMP = 0
module.exports = EventLogger = module.exports = EventLogger =
MAX_EVENTS_BEFORE_CLEAN: 100000
MAX_STALE_TIME_IN_MS: 3600 * 1000 MAX_STALE_TIME_IN_MS: 3600 * 1000
checkEventOrder: (message_id, message) -> checkEventOrder: (message_id, message) ->
@ -35,8 +34,9 @@ module.exports = EventLogger =
EVENT_LOG_COUNTER[key] = count EVENT_LOG_COUNTER[key] = count
EVENT_LOG_TIMESTAMP[key] = now EVENT_LOG_TIMESTAMP[key] = now
# periodically remove old counts # periodically remove old counts
if (++EVENT_COUNT % EventLogger.MAX_EVENTS_BEFORE_CLEAN) == 0 if (now - EVENT_LAST_CLEAN_TIMESTAMP) > EventLogger.MAX_STALE_TIME_IN_MS
EventLogger._cleanEventStream(now) EventLogger._cleanEventStream(now)
EVENT_LAST_CLEAN_TIMESTAMP = now
return previous return previous
_cleanEventStream: (now) -> _cleanEventStream: (now) ->