istox 0.1.150.2 → 0.1.151.pre.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- istox (0.1.150.1)
4
+ istox (0.1.148)
5
5
  awesome_print
6
6
  binding_of_caller
7
7
  bunny (>= 2.12.0)
@@ -65,7 +65,7 @@ GEM
65
65
  arel (9.0.0)
66
66
  awesome_print (1.8.0)
67
67
  aws-eventstream (1.1.0)
68
- aws-sigv4 (1.1.3)
68
+ aws-sigv4 (1.1.1)
69
69
  aws-eventstream (~> 1.0, >= 1.0.2)
70
70
  binding_of_caller (0.8.0)
71
71
  debug_inspector (>= 0.0.1)
@@ -98,18 +98,18 @@ GEM
98
98
  ffi (1.12.2)
99
99
  globalid (0.4.2)
100
100
  activesupport (>= 4.2.0)
101
- google-protobuf (3.11.4)
101
+ google-protobuf (3.11.4-universal-darwin)
102
102
  googleapis-common-protos-types (1.0.5)
103
103
  google-protobuf (~> 3.11)
104
104
  graphlient (0.3.7)
105
105
  faraday
106
106
  faraday_middleware
107
107
  graphql-client
108
- graphql (1.10.8)
108
+ graphql (1.10.6)
109
109
  graphql-client (0.16.0)
110
110
  activesupport (>= 3.0)
111
111
  graphql (~> 1.8)
112
- grpc (1.28.0)
112
+ grpc (1.28.0-universal-darwin)
113
113
  google-protobuf (~> 3.11)
114
114
  googleapis-common-protos-types (~> 1.0)
115
115
  grpc-tools (1.28.0)
data/lib/istox.rb CHANGED
@@ -33,7 +33,6 @@ module Istox
33
33
  require 'istox/helpers/regex_helper'
34
34
  require 'istox/helpers/result_handler'
35
35
  require 'istox/helpers/redis'
36
- require 'istox/helpers/dlm'
37
36
  require 'istox/helpers/remote_model_cache'
38
37
  require 'istox/models/blockchain_receipt'
39
38
  require 'istox/models/concerns/blockchain_receipt_query'
@@ -252,6 +252,7 @@ module Istox
252
252
  end
253
253
 
254
254
  def queue_ok?(conn, name)
255
+ Logger "queue_ok? #{name}"
255
256
  ch = conn.create_channel
256
257
  begin
257
258
  q = ch.queue(name, passive: true)
@@ -1,6 +1,10 @@
1
+ require 'redlock'
2
+
1
3
  module Istox
2
4
  class DLMBoot
3
5
  class << self
6
+ private
7
+
4
8
  def lock(key, timeout = 3600, db)
5
9
  loop do
6
10
  break if ::Istox::RedisBoot.sets(key, 1, {nx: true, px: timeout}, db)
@@ -54,40 +54,6 @@ module Istox
54
54
  end
55
55
 
56
56
  @connection = ::Istox::BunnyBoot.connection
57
-
58
- # Start a thread to sweep @channel
59
- Thread.new do
60
- loop do
61
- Thread.new do
62
- sleep 60 * 5
63
-
64
- tid = []
65
- Thread.list.each do |t|
66
- tid << t.object_id
67
- end
68
- # log.info("Current tid is #{tid}")
69
-
70
- tid_c = @channel.keys
71
- # log.info("@channel tid is #{tid_c}")
72
-
73
- tid_c.each do |t|
74
- unless tid.include? t
75
- # Close channel and remove it from @channel
76
- log.debug("Thread #{t} doesn't exist any more, close channel for it and remove it from @channel")
77
- @channel[t]['confirm-0'].close
78
- @channel[t]['confirm-1'].close
79
- @channel[t]['noconfirm'].close
80
- @channel.delete t
81
-
82
- # Remove exchange from @exchange
83
- @exchanges.delete t
84
- end
85
- end
86
- end.join
87
- end
88
- end
89
-
90
- @connection
91
57
  end
92
58
  end
93
59
 
@@ -111,6 +77,39 @@ module Istox
111
77
  @channel[Thread.current.object_id]['confirm-1'] = ::Istox::BunnyBoot.channel(connection, confirm: true)
112
78
  @channel[Thread.current.object_id]['noconfirm'] = ::Istox::BunnyBoot.channel(connection, confirm: false)
113
79
 
80
+ threadId = Thread.current.object_id
81
+ # Start new thread on receiving ACK from 'confirm-1' channel on the specified thread
82
+ Thread.new do
83
+ loop do
84
+ sleep 5
85
+
86
+ begin
87
+ success = @channel[threadId]['confirm-1'].wait_for_confirms
88
+ if success
89
+ ::Istox::BunnyBoot.del_tracker_on_channel @channel[threadId]['confirm-1'].id
90
+ else
91
+ @channel[threadId]['confirm-1'].nacked_set.each do |n|
92
+ log.debug("Publish Error[Async #{threadId}]: UNACK delivery tag is #{n}, republish message")
93
+ eid = ::Istox::BunnyBoot.find_tracker_on_channel @channel[threadId]['confirm-1'].id, n, 'eid'
94
+ payload = ::Istox::BunnyBoot.find_tracker_on_channel @channel[threadId]['confirm-1'].id, n, 'payload'
95
+ payload = JSON.parse(payload, :symbolize_names => true) unless payload.nil?
96
+ options = ::Istox::BunnyBoot.find_tracker_on_channel @channel[threadId]['confirm-1'].id, n, 'options'
97
+ options = JSON.parse(options, :symbolize_names => true) unless options.nil?
98
+ if options.nil?
99
+ routing_key = nil
100
+ else
101
+ routing_key = options.delete :routing_key
102
+ options[:delivery_tag] = n
103
+ end
104
+ publish(exchange: eid, routing_key: routing_key, message: payload, options: options)
105
+ end
106
+ end
107
+ rescue => e
108
+ # log.debug "wait_for_confirm error happening: #{e}"
109
+ end
110
+ end
111
+ end
112
+
114
113
  @channel[Thread.current.object_id]
115
114
  end
116
115
 
@@ -133,8 +132,7 @@ module Istox
133
132
 
134
133
  def channel_from_mode(mode)
135
134
  if mode == 0 || mode == 1
136
- # Currently we use mode 0 only
137
- channel["confirm-0"]
135
+ channel["confirm-#{mode.to_s}"]
138
136
  else
139
137
  channel['noconfirm']
140
138
  end
@@ -236,16 +234,7 @@ module Istox
236
234
  sleep 1
237
235
  do_publish(ex,options,message)
238
236
  rescue => e
239
- log.debug "Error happens: #{e.message}"
240
-
241
- # If the error indicates that the channel is already closed
242
- # then clear hash @channel and @exchange
243
- if e.message.include? "cannot use a closed channel"
244
- @channel.delete Thread.current.object_id
245
- @exchanges.delete Thread.current.object_id
246
- ex = exchange(eid)
247
- do_publish(ex, options, message)
248
- end
237
+ log.debug "Error happens: #{e}"
249
238
  end
250
239
  end
251
240
  end
@@ -48,7 +48,7 @@ module Istox
48
48
  end
49
49
  end
50
50
 
51
- def get(key:, field:)
51
+ def get(key:, field:, auto_convert_openstruct: true)
52
52
  raise 'You must provide a callback block if cache doesnt exist' unless block_given?
53
53
 
54
54
  key = key.to_s
@@ -60,7 +60,7 @@ module Istox
60
60
 
61
61
  if result.present?
62
62
  begin
63
- return ::Istox::CommonHelper.to_open_struct(JSON.parse(result))
63
+ return auto_convert_openstruct ? ::Istox::CommonHelper.to_open_struct(JSON.parse(result)) : result
64
64
  rescue StandardError => e
65
65
  log.warn('Unable to process result from cache store, is it not a json?')
66
66
  log.warn(e)
@@ -104,7 +104,7 @@ module Istox
104
104
  break unless ::Istox::BunnyBoot.queue_single_consumer? consumer_key
105
105
 
106
106
  flag = false
107
- ::Istox::DLMBoot.lock("peatio:#{consumer_key}:locking", 10) do
107
+ ::Istox::DLMBoot.lock("peatio:#{consumer_key}:locking", 5) do
108
108
  flag = ::Istox::BunnyBoot.queue_ok? @conn, queue.name
109
109
  end
110
110
  break if flag
data/lib/istox/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Istox
2
- VERSION = '0.1.150.2'.freeze
2
+ VERSION = '0.1.151-1'.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.1.150.2
4
+ version: 0.1.151.pre.1
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-06-03 00:00:00.000000000 Z
11
+ date: 2020-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: awesome_print
@@ -471,11 +471,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
471
471
  version: '0'
472
472
  required_rubygems_version: !ruby/object:Gem::Requirement
473
473
  requirements:
474
- - - ">="
474
+ - - ">"
475
475
  - !ruby/object:Gem::Version
476
- version: '0'
476
+ version: 1.3.1
477
477
  requirements: []
478
- rubygems_version: 3.0.8
478
+ rubygems_version: 3.0.3
479
479
  signing_key:
480
480
  specification_version: 4
481
481
  summary: istox backend shared gem