Skip to content

Commit

Permalink
follow new Airbrake API exception or message
Browse files Browse the repository at this point in the history
  • Loading branch information
joel committed Mar 2, 2017
1 parent 2391fbd commit 8720b6a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
26 changes: 18 additions & 8 deletions lib/airbrake_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,24 +59,34 @@ def safe_notify(exception)
unless authorized_to_notify?(redis_key)
raise TooManyNotification.new("#{redis_key} was notified too many times")
end

yield
end

def key(exception)
"#{KEY_PREFIX}#{(exception&.message || exception.inspect).parameterize}"
def key(exception_or_message)
msg = case exception_or_message
when String
exception_or_message
when StandardError, Exception
exception_or_message.message
else
exception_or_message.to_s
end
"#{KEY_PREFIX}#{msg.parameterize}"
end

def authorized_to_notify?(key)
return false if RedisProxy.get(key).to_i >= THRESHOLD # We won't hint Redis#incr(key) to not reset timelife of key
mark_as_notify(key) # return value is a true predicate
mark_as_notify!(key) # return value is a true predicate
true
end

def mark_as_notify(key)
unless RedisProxy.exists(key)
RedisProxy.set(key, 0)
RedisProxy.expire(key, T_5_HOURS)
end
def mark_as_notify!(key)
RedisProxy.multi
RedisProxy.incr(key)
RedisProxy.expire(key, T_1_HOUR)
RedisProxy.exec
nil
end

private
Expand Down
2 changes: 1 addition & 1 deletion lib/airbrake_proxy/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module AirbrakeProxy
VERSION = "0.1.1"
VERSION = "0.1.2"
end

0 comments on commit 8720b6a

Please sign in to comment.