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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 1408d4cc1f8842db0668e7a857a9d0dc461f0d82
4
- data.tar.gz: f26a1f4dd85c156717b08bd308df2dcfc1c07706
2
+ SHA256:
3
+ metadata.gz: cee83a3ed2329dd90ca0e12a8720c46225e90e2334a0a1d614cd911dbcfe02b4
4
+ data.tar.gz: 4d48b2dc61f9c7561788676d0cb9c3ada34edd1ff244f80e86c796236be7c819
5
5
  SHA512:
6
- metadata.gz: 37d1cb66a774f725ebceb176ec8ac013f8699b87983a8dc64d78beb32a8864fb9dcf93857a6e463f45d75f885c0bf6d4718e54d07dc5403c60e0566333473b52
7
- data.tar.gz: 8289a677da35316332fe57eb6167e412aaff6078d1aa4ed2a6813b715bda991c0e41c311f2b890ce8f5e68840959fb23b9fed14ec8f6e8d602fee513bd4e1d5c
6
+ metadata.gz: d0d61d258911181604c231b43e8711c09be4d74be10d7ed7d278fc28a438a1ec9f89a4a6e65cfdd0a0ae404f126058159ed55874bfcb71251514c1c27293ee01
7
+ data.tar.gz: 55308b0cf3a655fdb9f0c0d192e87f248ebfd2a966447df893000de29f5e5b6531816890f3b90a47c6087a09ffad0df58cb5ba04e07c3ba8262b068ecadf85d3
@@ -1,7 +1,10 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
- - 2.4.2
4
+ - 2.4.10
5
+ - 2.5.8
6
+ - 2.6.6
7
+ - 2.7.1
5
8
  deploy:
6
9
  skip_cleanup: true
7
10
  provider: rubygems
@@ -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 the client sends a request with the same idempotency key:
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.
@@ -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', '~> 1.15'
27
- spec.add_development_dependency 'rake', '~> 10.0'
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 = 429
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
@@ -1,3 +1,3 @@
1
1
  module IdempotentRequest
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
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.5
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: 2018-12-13 00:00:00.000000000 Z
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: '1.15'
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: '1.15'
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: '10.0'
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: '10.0'
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
- rubyforge_project:
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.