-
-
Save Eric-Guo/9374e8ef663d0704550916c78e247701 to your computer and use it in GitHub Desktop.
throttle exceptions (see https://github.com/smartinez87/exception_notification/issues/106)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
config.ignore_if do |exception, options| | |
# use beginning to prevent non unique keys (they include object ids and such) | |
key = exception.message.split("for").first[0..30] | |
ExpirableKey.new(key).exist_with_renew | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ExpirableKey | |
attr_accessor :key, :redis, :expire_in | |
def initialize(key, connection: Redis.current, expire_in: 60) | |
self.redis = connection | |
self.expire_in = expire_in | |
self.key = key | |
end | |
def exist? | |
redis.get(key).present? | |
end | |
def empty? | |
not(exist?) | |
end | |
def exist_with_renew?(value: true) | |
result = exist? | |
set(value) | |
result | |
end | |
def set(value = true) | |
redis.set(key, value) | |
redis.expire(key, expire_in) if expire_in.present? | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment