istox 0.1.128 → 0.1.129
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/.idea/istox-gem.iml +1694 -2
- data/Gemfile.lock +3 -3
- data/lib/istox/helpers/blockchain_service.rb +7 -5
- data/lib/istox/helpers/bunny_boot.rb +22 -9
- data/lib/istox/helpers/messaging.rb +12 -0
- data/lib/istox/helpers/publisher.rb +9 -2
- data/lib/istox/helpers/redis.rb +18 -18
- data/lib/istox/helpers/subscriber.rb +1 -1
- data/lib/istox/version.rb +1 -1
- metadata +3 -3
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
istox (0.1.
|
4
|
+
istox (0.1.129)
|
5
5
|
awesome_print
|
6
6
|
binding_of_caller
|
7
7
|
bunny (>= 2.12.0)
|
@@ -97,7 +97,7 @@ GEM
|
|
97
97
|
ffi (1.12.2)
|
98
98
|
globalid (0.4.2)
|
99
99
|
activesupport (>= 4.2.0)
|
100
|
-
google-protobuf (3.11.4)
|
100
|
+
google-protobuf (3.11.4-universal-darwin)
|
101
101
|
googleapis-common-protos-types (1.0.4)
|
102
102
|
google-protobuf (~> 3.0)
|
103
103
|
graphlient (0.3.7)
|
@@ -108,7 +108,7 @@ GEM
|
|
108
108
|
graphql-client (0.16.0)
|
109
109
|
activesupport (>= 3.0)
|
110
110
|
graphql (~> 1.8)
|
111
|
-
grpc (1.27.0)
|
111
|
+
grpc (1.27.0-universal-darwin)
|
112
112
|
google-protobuf (~> 3.11)
|
113
113
|
googleapis-common-protos-types (~> 1.0)
|
114
114
|
grpc-tools (1.27.0)
|
@@ -23,7 +23,7 @@ module Istox
|
|
23
23
|
# create blockchain receipt first
|
24
24
|
klass = blockchain_receipt_class
|
25
25
|
uuid = ::SecureRandom.uuid
|
26
|
-
receipt = klass.create!(
|
26
|
+
@receipt = klass.create!(
|
27
27
|
txid: uuid,
|
28
28
|
sid: sid,
|
29
29
|
is_request: is_request,
|
@@ -40,7 +40,7 @@ module Istox
|
|
40
40
|
klass.where(resource_name: model.class.name, resource_id: model.id).destroy_all
|
41
41
|
|
42
42
|
# then update receipt
|
43
|
-
receipt.update!(resource_id: model.id, resource_name: model.class.name)
|
43
|
+
@receipt.update!(resource_id: model.id, resource_name: model.class.name)
|
44
44
|
|
45
45
|
# execute the actual call to chainhub
|
46
46
|
result = execute.call(uuid)
|
@@ -50,7 +50,7 @@ module Istox
|
|
50
50
|
count = result.send('txn_count')
|
51
51
|
|
52
52
|
if count.to_i <= 0
|
53
|
-
receipt&.destroy!
|
53
|
+
@receipt&.destroy!
|
54
54
|
chainhub_processing = false
|
55
55
|
end
|
56
56
|
end
|
@@ -58,7 +58,7 @@ module Istox
|
|
58
58
|
|
59
59
|
chainhub_processing
|
60
60
|
rescue StandardError => e
|
61
|
-
receipt&.destroy
|
61
|
+
@receipt&.destroy
|
62
62
|
raise e
|
63
63
|
end
|
64
64
|
|
@@ -67,7 +67,9 @@ module Istox
|
|
67
67
|
|
68
68
|
blockchain_receipt_klass = get_blockchain_receipt_klass
|
69
69
|
klass = class_eval("::#{blockchain_receipt_klass.name}", __FILE__, __LINE__)
|
70
|
-
|
70
|
+
unless klass <= ::Istox::BlockchainReceipt
|
71
|
+
raise "#{blockchain_receipt_klass.name} does not inherit istox blockchain receipt"
|
72
|
+
end
|
71
73
|
|
72
74
|
klass
|
73
75
|
end
|
@@ -44,6 +44,19 @@ module Istox
|
|
44
44
|
nil
|
45
45
|
end
|
46
46
|
|
47
|
+
def binding_exchange_id(id)
|
48
|
+
data[:binding][id][:exchange] || :default
|
49
|
+
rescue
|
50
|
+
nil
|
51
|
+
end
|
52
|
+
|
53
|
+
def binding_routing_key(id)
|
54
|
+
queue = data[:binding][id][:queue]
|
55
|
+
data[:queues][queue][:queue_name]
|
56
|
+
rescue
|
57
|
+
nil
|
58
|
+
end
|
59
|
+
|
47
60
|
def confirm_mode(eid)
|
48
61
|
data[:exchanges][eid][:confirm] || -1
|
49
62
|
rescue
|
@@ -225,9 +238,9 @@ module Istox
|
|
225
238
|
# But each retry, there is new delivery_tag that should be updated
|
226
239
|
id = "#{channel_id.to_s}:#{delivery_tag.to_s}"
|
227
240
|
|
228
|
-
::Istox::RedisBoot.sets("#{id}:payload", payload.to_s)
|
229
|
-
::Istox::RedisBoot.sets("#{id}:eid", eid.to_s)
|
230
|
-
::Istox::RedisBoot.sets("#{id}:options", options.to_s)
|
241
|
+
::Istox::RedisBoot.sets("#{id}:payload", payload.to_s, 4)
|
242
|
+
::Istox::RedisBoot.sets("#{id}:eid", eid.to_s, 4)
|
243
|
+
::Istox::RedisBoot.sets("#{id}:options", options.to_s, 4)
|
231
244
|
end
|
232
245
|
|
233
246
|
def find_tracker_on_channel(channel_id, delivery_tag, key)
|
@@ -239,16 +252,16 @@ module Istox
|
|
239
252
|
def del_tracker_on_channel(channel_id)
|
240
253
|
trackers = find_trackers "#{channel_id}*"
|
241
254
|
trackers.each do |k|
|
242
|
-
::Istox::RedisBoot.del k
|
255
|
+
::Istox::RedisBoot.del k, 4
|
243
256
|
end
|
244
257
|
end
|
245
258
|
|
246
259
|
def rename_tracker(channel_id, old_delivery_tag, new_delivery_tag)
|
247
260
|
old_id = "#{channel_id}:#{old_delivery_tag}"
|
248
261
|
new_id = "#{channel_id}:#{new_delivery_tag}"
|
249
|
-
::Istox::RedisBoot.rename("#{old_id}:payload", "#{new_id}:payload")
|
250
|
-
::Istox::RedisBoot.rename("#{old_id}:eid", "#{new_id}:eid")
|
251
|
-
::Istox::RedisBoot.rename("#{old_id}:options", "#{new_id}:options")
|
262
|
+
::Istox::RedisBoot.rename("#{old_id}:payload", "#{new_id}:payload", 4)
|
263
|
+
::Istox::RedisBoot.rename("#{old_id}:eid", "#{new_id}:eid", 4)
|
264
|
+
::Istox::RedisBoot.rename("#{old_id}:options", "#{new_id}:options", 4)
|
252
265
|
end
|
253
266
|
|
254
267
|
def eid(ex)
|
@@ -295,11 +308,11 @@ module Istox
|
|
295
308
|
end
|
296
309
|
|
297
310
|
def find_trackers(pattern)
|
298
|
-
::Istox::RedisBoot.keys(pattern)
|
311
|
+
::Istox::RedisBoot.keys(pattern, 4)
|
299
312
|
end
|
300
313
|
|
301
314
|
def get_tracker(key)
|
302
|
-
::Istox::RedisBoot.get(key)
|
315
|
+
::Istox::RedisBoot.get(key, 4)
|
303
316
|
end
|
304
317
|
end
|
305
318
|
end
|
@@ -26,6 +26,9 @@ module Istox
|
|
26
26
|
subject: subject || 'Message from iSTOX',
|
27
27
|
body: content
|
28
28
|
}
|
29
|
+
},
|
30
|
+
options: {
|
31
|
+
confirm: 0
|
29
32
|
}
|
30
33
|
)
|
31
34
|
end
|
@@ -51,6 +54,9 @@ module Istox
|
|
51
54
|
template_name: template_name,
|
52
55
|
template_data_arr_json: template_data_arr.to_json
|
53
56
|
}
|
57
|
+
},
|
58
|
+
options: {
|
59
|
+
confirm: 0
|
54
60
|
}
|
55
61
|
)
|
56
62
|
end
|
@@ -86,6 +92,9 @@ module Istox
|
|
86
92
|
body: content,
|
87
93
|
attachments_json: attachments&.to_json
|
88
94
|
}
|
95
|
+
},
|
96
|
+
options: {
|
97
|
+
confirm: 0
|
89
98
|
}
|
90
99
|
)
|
91
100
|
end
|
@@ -117,6 +126,9 @@ module Istox
|
|
117
126
|
template_data_arr_json: template_data_arr.to_json,
|
118
127
|
attachments_json: attachments&.to_json
|
119
128
|
}
|
129
|
+
},
|
130
|
+
options: {
|
131
|
+
confirm: 0
|
120
132
|
}
|
121
133
|
)
|
122
134
|
end
|
@@ -12,8 +12,15 @@ module Istox
|
|
12
12
|
# extra publish options: {
|
13
13
|
# publish_confirm: true/false
|
14
14
|
# }
|
15
|
-
def publish(exchange: nil, routing_key: nil, message:, options: {})
|
16
|
-
|
15
|
+
def publish(exchange: nil, routing_key: nil, binding:nil, binding_suffix:nil, message:, options: {})
|
16
|
+
|
17
|
+
if exchange.nil? && routing_key.nil?
|
18
|
+
raise 'Exchange and routing key cannot be nil at the same time.' if binding.nil?
|
19
|
+
exchange = ::Istox::BunnyBoot.binding_exchange_id(binding)
|
20
|
+
raise "Can not find exchange for binding it #{binding}" if exchange.nil?
|
21
|
+
routing_key = ::Istox::BunnyBoot.binding_routing_key(binding)
|
22
|
+
routing_key = "#{routing_key}.#{binding_suffix}" unless binding_suffix.nil?
|
23
|
+
end
|
17
24
|
|
18
25
|
exchange = ::Istox::BunnyBoot.search_exchange_of_routing_key!(routing_key) if routing_key.present? && exchange.nil?
|
19
26
|
ex = exchange(exchange)
|
data/lib/istox/helpers/redis.rb
CHANGED
@@ -4,49 +4,49 @@ module Istox
|
|
4
4
|
class RedisBoot
|
5
5
|
class << self
|
6
6
|
|
7
|
-
def sets(k,v, options = {})
|
8
|
-
redis.set(k,v, options)
|
7
|
+
def sets(k,v, options = {}, db)
|
8
|
+
redis(db).set(k,v, options)
|
9
9
|
end
|
10
10
|
|
11
|
-
def keys(p)
|
12
|
-
redis.keys p
|
11
|
+
def keys(p, db)
|
12
|
+
redis(db).keys p
|
13
13
|
end
|
14
14
|
|
15
|
-
def del(k)
|
16
|
-
redis.del(k)
|
15
|
+
def del(k, db)
|
16
|
+
redis(db).del(k)
|
17
17
|
end
|
18
18
|
|
19
|
-
def get(k)
|
20
|
-
redis.get(k)
|
19
|
+
def get(k, db)
|
20
|
+
redis(db).get(k)
|
21
21
|
end
|
22
22
|
|
23
|
-
def flushdb
|
24
|
-
redis.flushdb
|
23
|
+
def flushdb(db)
|
24
|
+
redis(db).flushdb
|
25
25
|
end
|
26
26
|
|
27
|
-
def incr(k)
|
28
|
-
redis.incr(k)
|
27
|
+
def incr(k, db)
|
28
|
+
redis(db).incr(k)
|
29
29
|
end
|
30
30
|
|
31
|
-
def rename(old, new)
|
32
|
-
redis.rename old, new
|
31
|
+
def rename(old, new, db)
|
32
|
+
redis(db).rename old, new
|
33
33
|
end
|
34
34
|
|
35
|
-
def lock(key, timeout = 3600)
|
35
|
+
def lock(key, timeout = 3600, db)
|
36
36
|
loop do
|
37
|
-
break if
|
37
|
+
break if sets(key, 1, {nx: true, px: timeout}, db)
|
38
38
|
end
|
39
39
|
|
40
40
|
begin
|
41
41
|
yield
|
42
42
|
ensure
|
43
|
-
del key
|
43
|
+
del key, db
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
47
|
private
|
48
48
|
|
49
|
-
def redis(db
|
49
|
+
def redis(db)
|
50
50
|
@redis ||= Redis.new(
|
51
51
|
url: ENV["REDIS_URL"] || 'redis://127.0.0.1',
|
52
52
|
db: db
|
@@ -105,7 +105,7 @@ module Istox
|
|
105
105
|
break unless ::Istox::BunnyBoot.queue_single_consumer? consumer_key
|
106
106
|
|
107
107
|
flag = false
|
108
|
-
::Istox::RedisBoot.lock("peatio:#{consumer_key}:locking") do
|
108
|
+
::Istox::RedisBoot.lock("peatio:#{consumer_key}:locking", 4) do
|
109
109
|
flag = ::Istox::BunnyBoot.queue_ok? @conn, queue.name
|
110
110
|
end
|
111
111
|
break if flag
|
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.1.
|
4
|
+
version: 0.1.129
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Siong Leng
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-03-
|
11
|
+
date: 2020-03-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: awesome_print
|
@@ -445,7 +445,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
445
445
|
- !ruby/object:Gem::Version
|
446
446
|
version: '0'
|
447
447
|
requirements: []
|
448
|
-
rubygems_version: 3.0.
|
448
|
+
rubygems_version: 3.0.8
|
449
449
|
signing_key:
|
450
450
|
specification_version: 4
|
451
451
|
summary: istox backend shared gem
|