istox 0.2.13 → 0.2.14

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a4360b1a18d0d8d953665294d793c1f32e30b8fe87ea54635bb91ae3913666b4
4
- data.tar.gz: bb9ea9f532da561d5cf6d527af3ee16e25a4952162a40fc5b0c991099caf82da
3
+ metadata.gz: ca1e8a56cf58ec65db8e7c74bce91228a9c58f6fac41fba4dd8569263fe293ae
4
+ data.tar.gz: e222955b4c24d1422f43cccc266251d77bf79322df1d3b6e24c7e8e598ced3cd
5
5
  SHA512:
6
- metadata.gz: d99fffea40090ffa46dd6ed6baa0197d57a4a2a73a701996740a9083893324a2be2571630ab583eeb25be9e91dc66ee8cf3ea85fd386193e8a035f5a55881aa9
7
- data.tar.gz: 163cce847ce4f4d83d81f4d47e8c6452f4cf1344b49fadeeac8f634be50cba292bd462047521b580c0650b17621b9b0a14a0efe526f88edd43fbfcfd22c1709e
6
+ metadata.gz: 293000d6656fc803c265a7dd025824a782895bb86d50c4b9e64f1c3a53b64695c68b5b72498aeff9750a800522368811371bf5d6657b2a7b39fb531141d33ca5
7
+ data.tar.gz: a12c26ffb85108b2b664245f57e5cf86dbd6a3dbc952dcf5c06d3d01fff1bcdeaffd5a68792c172bfd4722166dac74d26fdaaa2887afe6c154c63b2860fa22d7
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- istox (0.2.12)
4
+ istox (0.2.13)
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.41.0)
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,32 +112,36 @@ GEM
112
112
  i18n (~> 0.5)
113
113
  fakeredis (0.7.0)
114
114
  redis (>= 3.2, < 5.0)
115
- faraday (1.4.3)
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.1.0)
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
137
  google-protobuf (3.17.3)
134
- googleapis-common-protos-types (1.0.6)
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.12)
144
+ graphql (1.12.14)
141
145
  graphql-client (0.16.0)
142
146
  activesupport (>= 3.0)
143
147
  graphql (~> 1.8)
@@ -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.11.7)
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.4)
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,10 @@ 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
+
42
47
  # delete the previous existing blockchain receipts
43
48
  klass.where(resource_name: model.class.name, resource_id: model.id).destroy_all
44
49
 
@@ -57,11 +62,14 @@ module Istox
57
62
  chainhub_processing = false
58
63
  end
59
64
  end
65
+
66
+ ::Istox::RaceConditionHelper.release(key) if is_request
60
67
  end
61
68
 
62
69
  chainhub_processing
63
70
  rescue StandardError => e
64
71
  receipt&.destroy
72
+ ::Istox::RaceConditionHelper.release(key) if is_request && key.present?
65
73
  raise e
66
74
  end
67
75
 
@@ -0,0 +1,26 @@
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
+ # if result false means the key already exist
14
+ result
15
+ end
16
+
17
+ def release(key)
18
+ request_redis.del('race-condition||' + key.to_s)
19
+ end
20
+
21
+ def request_redis
22
+ @request_redis ||= ::Istox::RedisManager.request_redis
23
+ end
24
+ end
25
+ end
26
+ end
data/lib/istox/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Istox
2
- VERSION = '0.2.13'.freeze
2
+ VERSION = '0.2.14'.freeze
3
3
  end
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.13
4
+ version: 0.2.14
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-06 00:00:00.000000000 Z
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