idempotent-request 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +4 -1
- data/CHANGELOG.md +5 -0
- data/README.md +24 -2
- data/idempotent-request.gemspec +2 -2
- data/lib/idempotent-request/middleware.rb +2 -1
- data/lib/idempotent-request/request_manager.rb +2 -2
- data/lib/version.rb +1 -1
- metadata +11 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: cee83a3ed2329dd90ca0e12a8720c46225e90e2334a0a1d614cd911dbcfe02b4
|
4
|
+
data.tar.gz: 4d48b2dc61f9c7561788676d0cb9c3ada34edd1ff244f80e86c796236be7c819
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0d61d258911181604c231b43e8711c09be4d74be10d7ed7d278fc28a438a1ec9f89a4a6e65cfdd0a0ae404f126058159ed55874bfcb71251514c1c27293ee01
|
7
|
+
data.tar.gz: 55308b0cf3a655fdb9f0c0d192e87f248ebfd2a966447df893000de29f5e5b6531816890f3b90a47c6087a09ffad0df58cb5ba04e07c3ba8262b068ecadf85d3
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# Idempotent Request Changelog #
|
2
2
|
|
3
|
+
## v0.1.5 ##
|
4
|
+
|
5
|
+
* use ActiveSupport::Notifications to instrument events
|
6
|
+
* fix an issue when getting an exception inside application would not delete lock, so client could receive 429 after 500
|
7
|
+
|
3
8
|
## v0.1.4 ##
|
4
9
|
|
5
10
|
* Fix an issue, when http response from backend != 200..226 caused lock to be taken
|
data/README.md
CHANGED
@@ -84,6 +84,23 @@ module IdempotentRequest
|
|
84
84
|
end
|
85
85
|
```
|
86
86
|
|
87
|
+
|
88
|
+
### Use ActiveSupport::Notifications to read events
|
89
|
+
|
90
|
+
```ruby
|
91
|
+
# config/initializers/idempotent_request.rb
|
92
|
+
ActiveSupport::Notifications.subscribe('idempotent.request') do |name, start, finish, request_id, payload|
|
93
|
+
notification = payload[:request].env['idempotent.request']
|
94
|
+
if notification['read']
|
95
|
+
Rails.logger.info "IdempotentRequest: Hit cached response from key #{notification['key']}, response: #{notification['read']}"
|
96
|
+
elsif notification['write']
|
97
|
+
Rails.logger.info "IdempotentRequest: Write: key #{notification['key']}, status: #{notification['write'][0]}, headers: #{notification['write'][1]}, unlocked? #{notification['unlocked']}"
|
98
|
+
elsif notification['concurrent_request_response']
|
99
|
+
Rails.logger.warn "IdempotentRequest: Concurrent request detected with key #{notification['key']}"
|
100
|
+
end
|
101
|
+
end
|
102
|
+
```
|
103
|
+
|
87
104
|
## Custom options
|
88
105
|
|
89
106
|
```ruby
|
@@ -92,7 +109,8 @@ config.middleware.use IdempotentRequest::Middleware,
|
|
92
109
|
header_key: 'X-Qonto-Idempotency-Key', # by default Idempotency-key
|
93
110
|
policy: IdempotentRequest::Policy,
|
94
111
|
callback: IdempotentRequest::RailsCallback,
|
95
|
-
storage: IdempotentRequest::RedisStorage.new(::Redis.current, expire_time: 1.day, namespace: 'idempotency_keys')
|
112
|
+
storage: IdempotentRequest::RedisStorage.new(::Redis.current, expire_time: 1.day, namespace: 'idempotency_keys'),
|
113
|
+
conflict_response_status: 409
|
96
114
|
```
|
97
115
|
|
98
116
|
### Policy
|
@@ -117,7 +135,7 @@ end
|
|
117
135
|
|
118
136
|
### Callback
|
119
137
|
|
120
|
-
Get notified when
|
138
|
+
Get notified when a client sends a request with the same idempotency key:
|
121
139
|
|
122
140
|
```ruby
|
123
141
|
class RailsCallback
|
@@ -133,6 +151,10 @@ class RailsCallback
|
|
133
151
|
end
|
134
152
|
```
|
135
153
|
|
154
|
+
### Conflict response status
|
155
|
+
|
156
|
+
Define http status code that should be returned when a client sends concurrent requests with the same idempotency key.
|
157
|
+
|
136
158
|
## Contributing
|
137
159
|
|
138
160
|
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/idempotent-request. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
data/idempotent-request.gemspec
CHANGED
@@ -23,8 +23,8 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_dependency 'rack', '~> 2.0'
|
24
24
|
spec.add_dependency 'oj', '~> 3.0'
|
25
25
|
|
26
|
-
spec.add_development_dependency 'bundler'
|
27
|
-
spec.add_development_dependency 'rake', '
|
26
|
+
spec.add_development_dependency 'bundler'
|
27
|
+
spec.add_development_dependency 'rake', '>= 12.3.3'
|
28
28
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
29
29
|
spec.add_development_dependency 'fakeredis', '~> 0.6'
|
30
30
|
spec.add_development_dependency 'byebug', '~> 10.0'
|
@@ -5,6 +5,7 @@ module IdempotentRequest
|
|
5
5
|
@config = config
|
6
6
|
@policy = config.fetch(:policy)
|
7
7
|
@notifier = ActiveSupport::Notifications if defined?(ActiveSupport::Notifications)
|
8
|
+
@conflict_response_status = config.fetch(:conflict_response_status, 429)
|
8
9
|
end
|
9
10
|
|
10
11
|
def call(env)
|
@@ -45,7 +46,7 @@ module IdempotentRequest
|
|
45
46
|
end
|
46
47
|
|
47
48
|
def concurrent_request_response
|
48
|
-
status =
|
49
|
+
status = @conflict_response_status
|
49
50
|
headers = { 'Content-Type' => 'application/json' }
|
50
51
|
body = [ Oj.dump('error' => 'Concurrent requests detected') ]
|
51
52
|
request.env['idempotent.request']['concurrent_request_response'] = true
|
@@ -49,10 +49,10 @@ module IdempotentRequest
|
|
49
49
|
response: Array(response))
|
50
50
|
end
|
51
51
|
|
52
|
-
def run_callback(action, args)
|
52
|
+
def run_callback(action, **args)
|
53
53
|
return unless @callback
|
54
54
|
|
55
|
-
@callback.new(request).send(action, args)
|
55
|
+
@callback.new(request).send(action, **args)
|
56
56
|
end
|
57
57
|
|
58
58
|
def key
|
data/lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: idempotent-request
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dmytro Zakharov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -42,30 +42,30 @@ dependencies:
|
|
42
42
|
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 12.3.3
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 12.3.3
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -152,8 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
152
152
|
- !ruby/object:Gem::Version
|
153
153
|
version: '0'
|
154
154
|
requirements: []
|
155
|
-
|
156
|
-
rubygems_version: 2.6.14
|
155
|
+
rubygems_version: 3.0.8
|
157
156
|
signing_key:
|
158
157
|
specification_version: 4
|
159
158
|
summary: Rack middleware ensuring at most once requests for mutating endpoints.
|