istox 0.2.13 → 0.2.14.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +14 -10
- data/lib/istox.rb +1 -0
- data/lib/istox/helpers/blockchain_service.rb +11 -0
- data/lib/istox/helpers/race_condition_helper.rb +40 -0
- data/lib/istox/models/blockchain_receipt.rb +2 -0
- data/lib/istox/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 191d8ea6fdad58b0fe99961ac461eaaab8d80e684172b11632d056e27f9b6c92
|
4
|
+
data.tar.gz: c69b2ef4fbd2ee80619690ba61cd434f6f527f95ea2cb3c9dd44e35cc997200e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f3c49ba90cb39a0773de6bc7781d08c66e1db7356d214c2c971fd0dae7b4d0daa92c5e9fda2426df67cd2a8ffa13816d263946aab46ca564833ff6cc6e220b36
|
7
|
+
data.tar.gz: 78f888d34684fc979354b8bc13b781f0f9aee530c2ffa0f46285298f460dda6a96c235a47856b25e711cf853df5208a0e98e02b3e3d4c3080d14219697d84038
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
istox (0.2.
|
4
|
+
istox (0.2.14.2)
|
5
5
|
amazing_print
|
6
6
|
awesome_print
|
7
7
|
aws-sdk-sns (~> 1)
|
@@ -74,7 +74,7 @@ GEM
|
|
74
74
|
aws-partitions (~> 1, >= 1.239.0)
|
75
75
|
aws-sigv4 (~> 1.1)
|
76
76
|
jmespath (~> 1.0)
|
77
|
-
aws-sdk-sns (1.
|
77
|
+
aws-sdk-sns (1.42.0)
|
78
78
|
aws-sdk-core (~> 3, >= 3.112.0)
|
79
79
|
aws-sigv4 (~> 1.1)
|
80
80
|
aws-sdk-xray (1.4.0)
|
@@ -112,36 +112,40 @@ GEM
|
|
112
112
|
i18n (~> 0.5)
|
113
113
|
fakeredis (0.7.0)
|
114
114
|
redis (>= 3.2, < 5.0)
|
115
|
-
faraday (1.
|
115
|
+
faraday (1.5.1)
|
116
116
|
faraday-em_http (~> 1.0)
|
117
117
|
faraday-em_synchrony (~> 1.0)
|
118
118
|
faraday-excon (~> 1.1)
|
119
|
+
faraday-httpclient (~> 1.0.1)
|
119
120
|
faraday-net_http (~> 1.0)
|
120
121
|
faraday-net_http_persistent (~> 1.1)
|
122
|
+
faraday-patron (~> 1.0)
|
121
123
|
multipart-post (>= 1.2, < 3)
|
122
124
|
ruby2_keywords (>= 0.0.4)
|
123
125
|
faraday-em_http (1.0.0)
|
124
126
|
faraday-em_synchrony (1.0.0)
|
125
127
|
faraday-excon (1.1.0)
|
128
|
+
faraday-httpclient (1.0.1)
|
126
129
|
faraday-net_http (1.0.1)
|
127
|
-
faraday-net_http_persistent (1.
|
130
|
+
faraday-net_http_persistent (1.2.0)
|
131
|
+
faraday-patron (1.0.0)
|
128
132
|
faraday_middleware (1.0.0)
|
129
133
|
faraday (~> 1.0)
|
130
134
|
ffi (1.15.3)
|
131
135
|
globalid (0.4.2)
|
132
136
|
activesupport (>= 4.2.0)
|
133
|
-
google-protobuf (3.17.3)
|
134
|
-
googleapis-common-protos-types (1.0
|
137
|
+
google-protobuf (3.17.3-universal-darwin)
|
138
|
+
googleapis-common-protos-types (1.1.0)
|
135
139
|
google-protobuf (~> 3.14)
|
136
140
|
graphlient (0.5.0)
|
137
141
|
faraday (>= 1.0)
|
138
142
|
faraday_middleware
|
139
143
|
graphql-client
|
140
|
-
graphql (1.12.
|
144
|
+
graphql (1.12.14)
|
141
145
|
graphql-client (0.16.0)
|
142
146
|
activesupport (>= 3.0)
|
143
147
|
graphql (~> 1.8)
|
144
|
-
grpc (1.38.0)
|
148
|
+
grpc (1.38.0-universal-darwin)
|
145
149
|
google-protobuf (~> 3.15)
|
146
150
|
googleapis-common-protos-types (~> 1.0)
|
147
151
|
grpc-tools (1.38.0)
|
@@ -174,7 +178,7 @@ GEM
|
|
174
178
|
nokogiri (1.11.7)
|
175
179
|
mini_portile2 (~> 2.5.0)
|
176
180
|
racc (~> 1.4)
|
177
|
-
oj (3.
|
181
|
+
oj (3.12.2)
|
178
182
|
ougai (2.0.0)
|
179
183
|
oj (~> 3.10)
|
180
184
|
paranoia (2.4.3)
|
@@ -260,7 +264,7 @@ GEM
|
|
260
264
|
rspec-mocks (~> 3.8.0)
|
261
265
|
rspec-support (~> 3.8.0)
|
262
266
|
rspec-support (3.8.0)
|
263
|
-
ruby2_keywords (0.0.
|
267
|
+
ruby2_keywords (0.0.5)
|
264
268
|
set (1.0.1)
|
265
269
|
slop (4.9.1)
|
266
270
|
sorted_set (1.0.3)
|
data/lib/istox.rb
CHANGED
@@ -27,6 +27,7 @@ module Istox
|
|
27
27
|
require 'istox/helpers/graphql_client'
|
28
28
|
require 'istox/helpers/gruf_listener_hook'
|
29
29
|
require 'istox/helpers/messaging'
|
30
|
+
require 'istox/helpers/race_condition_helper'
|
30
31
|
require 'istox/helpers/blockchain_service'
|
31
32
|
require 'istox/helpers/f_math'
|
32
33
|
require 'istox/helpers/my_open_struct'
|
@@ -30,6 +30,7 @@ module Istox
|
|
30
30
|
request_reason: request_reason,
|
31
31
|
resource_action: action
|
32
32
|
)
|
33
|
+
key = nil
|
33
34
|
|
34
35
|
chainhub_processing = true
|
35
36
|
|
@@ -39,6 +40,13 @@ module Istox
|
|
39
40
|
# execute before proc, and get the model that blockchain receipt should bind to
|
40
41
|
model = before.call(uuid)
|
41
42
|
|
43
|
+
key = model.class.name + '-' + model.id.to_s
|
44
|
+
## for request there we need a lock to prevent there is not duplicate request exist for single model
|
45
|
+
::Istox::RaceConditionHelper.acquire!(key) if is_request
|
46
|
+
|
47
|
+
## validate the request, this validation is overridable by inherited class
|
48
|
+
receipt.validate_request!(model.class.name, model.id) if is_request
|
49
|
+
|
42
50
|
# delete the previous existing blockchain receipts
|
43
51
|
klass.where(resource_name: model.class.name, resource_id: model.id).destroy_all
|
44
52
|
|
@@ -57,11 +65,14 @@ module Istox
|
|
57
65
|
chainhub_processing = false
|
58
66
|
end
|
59
67
|
end
|
68
|
+
|
69
|
+
::Istox::RaceConditionHelper.release(key) if is_request
|
60
70
|
end
|
61
71
|
|
62
72
|
chainhub_processing
|
63
73
|
rescue StandardError => e
|
64
74
|
receipt&.destroy
|
75
|
+
::Istox::RaceConditionHelper.release(key) if is_request && key.present?
|
65
76
|
raise e
|
66
77
|
end
|
67
78
|
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Istox
|
2
|
+
class RaceConditionHelper
|
3
|
+
class << self
|
4
|
+
def acquire!(key, expired_seconds: 20)
|
5
|
+
result = acquire(key, expired_seconds: expired_seconds)
|
6
|
+
|
7
|
+
raise 'Duplicate request detected, please refresh the page and try again.' if result == false
|
8
|
+
end
|
9
|
+
|
10
|
+
def acquire(key, expired_seconds: 20)
|
11
|
+
result = request_redis.set('race-condition||' + key.to_s, 'EMPTY', nx: true, ex: expired_seconds.to_i.seconds)
|
12
|
+
|
13
|
+
log.info("Acquiring lock for key: #{key}, expired in #{expired_seconds} seconds, result: #{result}")
|
14
|
+
|
15
|
+
# if result false means the key already exist
|
16
|
+
result
|
17
|
+
end
|
18
|
+
|
19
|
+
def release(key)
|
20
|
+
request_redis.del('race-condition||' + key.to_s)
|
21
|
+
|
22
|
+
log.info("Releasing lock for key: #{key}")
|
23
|
+
end
|
24
|
+
|
25
|
+
### lock with block
|
26
|
+
def lock!(key, expired_seconds: 20)
|
27
|
+
acquire!(key, expired_seconds: expired_seconds)
|
28
|
+
yield
|
29
|
+
release(key)
|
30
|
+
rescue StandardError => e
|
31
|
+
release(key)
|
32
|
+
raise e
|
33
|
+
end
|
34
|
+
|
35
|
+
def request_redis
|
36
|
+
@request_redis ||= ::Istox::RedisManager.request_redis
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/istox/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: istox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.14.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Siong Leng
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-07-
|
11
|
+
date: 2021-07-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: amazing_print
|
@@ -495,6 +495,7 @@ files:
|
|
495
495
|
- lib/istox/helpers/order_book_price_time.rb
|
496
496
|
- lib/istox/helpers/order_book_prorate.rb
|
497
497
|
- lib/istox/helpers/publisher.rb
|
498
|
+
- lib/istox/helpers/race_condition_helper.rb
|
498
499
|
- lib/istox/helpers/rate_limit.rb
|
499
500
|
- lib/istox/helpers/redis_boot.rb
|
500
501
|
- lib/istox/helpers/redis_manager.rb
|