diff --git a/CHANGELOG.md b/CHANGELOG.md index cd2607e..d518137 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Idempotent Request Changelog # +## v0.1.5 ## + +* use ActiveSupport::Notifications to instrument events +* fix an issue when getting an exception inside application would not delete lock, so client could receive 429 after 500 + ## v0.1.4 ## * Fix an issue, when http response from backend != 200..226 caused lock to be taken diff --git a/README.md b/README.md index 675d130..0ddb544 100644 --- a/README.md +++ b/README.md @@ -84,6 +84,23 @@ module IdempotentRequest end ``` + +### Use ActiveSupport::Notifications to read events + +```ruby +# config/initializers/idempotent_request.rb +ActiveSupport::Notifications.subscribe('idempotent.request') do |name, start, finish, request_id, payload| + notification = payload[:request].env['idempotent.request'] + if notification['read'] + Rails.logger.info "IdempotentRequest: Hit cached response from key #{notification['key']}, response: #{notification['read']}" + elsif notification['write'] + Rails.logger.info "IdempotentRequest: Write: key #{notification['key']}, status: #{notification['write'][0]}, headers: #{notification['write'][1]}, unlocked? #{notification['unlocked']}" + elsif notification['concurrent_request_response'] + Rails.logger.warn "IdempotentRequest: Concurrent request detected with key #{notification['key']}" + end +end +``` + ## Custom options ```ruby