update changelog, add readme regardless usage of ActiveSupport::Notifications

This commit is contained in:
Dmytro Zakharov 2018-12-13 17:18:39 +01:00
parent 8f354b9883
commit 29f3709846
2 changed files with 22 additions and 0 deletions

View File

@ -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

View File

@ -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