istox 0.1.153.4 → 0.1.155

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: 65872c83f71e4c64acb4e856541411c2cf06afbb147fb500fe86d3ae647669d9
4
- data.tar.gz: 3b6c32750ad37e9efc5412be0ee61186267f906e4e850aa5de4a39d53423f975
3
+ metadata.gz: 833e7de03486bce73d7747c9cb1218c5bcfd0e1041b1ff4bc5a797f57a2cbfa4
4
+ data.tar.gz: 36fa1c03f1d658eb02eeff750138bbf3da8713fd0c9aacd98186eb4d6409aba0
5
5
  SHA512:
6
- metadata.gz: 7b4169651c930a4fec4d685b4109388e791e8bf283c57c87754618b80a00ca650f4e128a21117b1a96afb6cdf54f0b232b68d1a8c5fcd71c1bfbec0a446c39c4
7
- data.tar.gz: 803b1349d0ed3335dcc9994aeaeb01518c5e6a49f6523cdc904bed6083c87fdf02b69d40d0a48c8b6ed8ce3f9fece35f03ce39556ce0a169f4ab7613b6a56c34
6
+ metadata.gz: 41b28d09921c718c370aa8854038d769b57606c3db8326e777436059465b3123a502976b37d93d613881d0a1bd1f51449097013949dbade21a99dc26e885de77
7
+ data.tar.gz: 2b51a0694bf11bbf0c85665886abb1ff365e6a64950a47dfa5ef01752f172fdb6507b6343037801a149d12f7b1ae94d03bfcffd0f84a52a7e92c08e040fd526e
@@ -1,11 +1,12 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- istox (0.1.153.3)
4
+ istox (0.1.154.3)
5
5
  amazing_print
6
6
  awesome_print
7
7
  binding_of_caller
8
8
  bunny (>= 2.12.0)
9
+ exponential-backoff (= 0.0.4)
9
10
  graphlient
10
11
  gruf
11
12
  hashie (~> 3.5.7)
@@ -62,7 +63,7 @@ GEM
62
63
  i18n (>= 0.7, < 2)
63
64
  minitest (~> 5.1)
64
65
  tzinfo (~> 1.1)
65
- amazing_print (1.1.0)
66
+ amazing_print (1.2.0)
66
67
  amq-protocol (2.3.1)
67
68
  arel (9.0.0)
68
69
  awesome_print (1.8.0)
@@ -89,6 +90,7 @@ GEM
89
90
  uniform_notifier (~> 1.11.0)
90
91
  bunny (2.15.0)
91
92
  amq-protocol (~> 2.3, >= 2.3.1)
93
+ byebug (11.1.3)
92
94
  coderay (1.1.2)
93
95
  concurrent-ruby (1.1.6)
94
96
  crass (1.0.6)
@@ -96,6 +98,7 @@ GEM
96
98
  debug_inspector (0.0.3)
97
99
  diff-lcs (1.3)
98
100
  erubi (1.9.0)
101
+ exponential-backoff (0.0.4)
99
102
  factory_bot (4.8.2)
100
103
  activesupport (>= 3.0.0)
101
104
  factory_bot_rails (4.8.2)
@@ -109,10 +112,10 @@ GEM
109
112
  multipart-post (>= 1.2, < 3)
110
113
  faraday_middleware (1.0.0)
111
114
  faraday (~> 1.0)
112
- ffi (1.12.2)
115
+ ffi (1.13.1)
113
116
  globalid (0.4.2)
114
117
  activesupport (>= 4.2.0)
115
- google-protobuf (3.12.1-universal-darwin)
118
+ google-protobuf (3.12.2-universal-darwin)
116
119
  googleapis-common-protos-types (1.0.5)
117
120
  google-protobuf (~> 3.11)
118
121
  graphlient (0.4.0)
@@ -171,6 +174,9 @@ GEM
171
174
  pry (0.12.2)
172
175
  coderay (~> 1.1.0)
173
176
  method_source (~> 0.9.0)
177
+ pry-byebug (3.8.0)
178
+ byebug (~> 11.0)
179
+ pry (~> 0.10)
174
180
  pry-rails (0.3.9)
175
181
  pry (>= 0.10.4)
176
182
  rack (2.2.2)
@@ -259,7 +265,7 @@ GEM
259
265
  tzinfo (1.2.6)
260
266
  thread_safe (~> 0.1)
261
267
  uniform_notifier (1.11.0)
262
- vault (0.13.2)
268
+ vault (0.14.0)
263
269
  aws-sigv4
264
270
  websocket-driver (0.7.0)
265
271
  websocket-extensions (>= 0.1.0)
@@ -278,6 +284,7 @@ DEPENDENCIES
278
284
  fakeredis
279
285
  istox!
280
286
  pry
287
+ pry-byebug
281
288
  pry-rails
282
289
  rails (~> 5.2.1)
283
290
  rake (~> 10.0)
@@ -0,0 +1,93 @@
1
+ import sys
2
+ import re
3
+ from tempfile import mkstemp
4
+ from shutil import move, copymode
5
+ from os import fdopen, remove
6
+ import os
7
+
8
+ # HOW TO RUN: python bulk-update-version.py <version updating to, eg. 0.1.150.2>
9
+
10
+ SERVICES = ["client-api", "admin-api", "message-api", "auth", "admin-auth"]
11
+
12
+
13
+ def replace(file_path, pattern, subst):
14
+ # Create temp file
15
+ fh, abs_path = mkstemp()
16
+ with fdopen(fh, 'w') as new_file:
17
+ dirname = os.path.dirname(__file__)
18
+ file_path = os.path.join(dirname, file_path)
19
+ if os.path.exists(file_path) == False:
20
+ return
21
+ with open(file_path) as old_file:
22
+ for line in old_file:
23
+ new_file.write(re.sub(pattern, subst, line))
24
+ # Copy the file permissions from the old file to the new file
25
+ copymode(file_path, abs_path)
26
+ # Remove original file
27
+ remove(file_path)
28
+ # Move new file
29
+ move(abs_path, file_path)
30
+
31
+
32
+ def push_service(file_path, version, hotfix):
33
+ dirname = os.path.dirname(__file__)
34
+ file_path = os.path.join(dirname, file_path)
35
+
36
+ if os.path.exists(file_path) == False:
37
+ return
38
+
39
+ if hotfix == True:
40
+ branch_name = "hotfix"
41
+ else:
42
+ branch_name = "FIX/update-istox-gem-" + version
43
+
44
+ os.chdir(file_path)
45
+ os.system(
46
+ "git branch -D %s &>/dev/null" % (branch_name))
47
+ os.system("echo 'Deleted local branch'")
48
+ os.system(
49
+ "git push origin --delete %s &>/dev/null" % (branch_name))
50
+ os.system("echo 'Deleted remote branch'")
51
+ os.system("git fetch -a")
52
+ os.system("git checkout -b %s" % (branch_name))
53
+ os.system("git add Gemfile")
54
+ os.system("git commit -m 'Update istox-gem version to %s'" % (version))
55
+ os.system("git push --set-upstream origin %s" % (branch_name))
56
+ # os.system("cd " + file_path + " && git branch -D " +
57
+ # branch_name + " &>/dev/null || echo 'Deleted local branch' || git push origin --delete hotfix &>/dev/null || echo 'Deleted remote branch' || git fetch -a || git checkout -b " +
58
+ # branch_name + " && git add Gemfile && git commit -m 'Update istox-gem version to "
59
+ # + version + "' && git push --set-upstream origin " + branch_name)
60
+
61
+
62
+ arguments = sys.argv
63
+ arguments.pop(0)
64
+
65
+ new_version = arguments[0]
66
+
67
+ hotfix = False
68
+
69
+ while True:
70
+ result = raw_input("Is this a hotix? Y/N \n")
71
+
72
+ if result.lower() == 'y':
73
+ hotfix = True
74
+ break
75
+ elif result.lower() == 'n':
76
+ hotfix = False
77
+ break
78
+ else:
79
+ print("Please input only Y or N.")
80
+
81
+
82
+ print("Updating services " + str(SERVICES) +
83
+ " to istox-gem version " + new_version)
84
+
85
+ for service in SERVICES:
86
+ replace("../" + service + "/Gemfile", r"gem 'istox'.+",
87
+ "gem 'istox', '" + new_version + "'")
88
+
89
+ for service in SERVICES:
90
+ push_service("../" + service, new_version, hotfix)
91
+
92
+ print("Services " + str(SERVICES) +
93
+ " has been updated to istox-gem version " + new_version)
@@ -34,6 +34,7 @@ Gem::Specification.new do |spec|
34
34
  spec.add_dependency 'awesome_print'
35
35
  spec.add_dependency 'binding_of_caller'
36
36
  spec.add_dependency 'bunny', '>= 2.12.0'
37
+ spec.add_dependency 'exponential-backoff', '0.0.4'
37
38
  spec.add_dependency 'graphlient'
38
39
  spec.add_dependency 'gruf'
39
40
  spec.add_dependency 'hashie', '~> 3.5.7'
@@ -53,6 +54,7 @@ Gem::Specification.new do |spec|
53
54
  spec.add_development_dependency 'faker', '~> 1.7.3'
54
55
  spec.add_development_dependency 'fakeredis'
55
56
  spec.add_development_dependency 'pry'
57
+ spec.add_development_dependency 'pry-byebug'
56
58
  spec.add_development_dependency 'pry-rails'
57
59
  spec.add_development_dependency 'rails', '~> 5.2.1'
58
60
  spec.add_development_dependency 'rake', '~> 10.0'
@@ -36,6 +36,7 @@ module Istox
36
36
  require 'istox/helpers/redis_manager'
37
37
  require 'istox/helpers/dlm'
38
38
  require 'istox/helpers/remote_model_cache'
39
+ require 'istox/helpers/formatter'
39
40
 
40
41
  require 'istox/helpers/xray/grpc_client_xray_interceptor'
41
42
  require 'istox/helpers/xray/grpc_server_xray_interceptor'
@@ -215,7 +215,7 @@ module Istox
215
215
  retry_limit = queue_config_from_consumer_key!(consumer_key)['retry_limit']
216
216
 
217
217
  if retry_limit.nil?
218
- 3
218
+ 5
219
219
  else
220
220
  retry_limit.to_i
221
221
  end
@@ -234,6 +234,10 @@ module Istox
234
234
  end
235
235
  end
236
236
 
237
+ def queue_retry_gap_set?(consumer_key)
238
+ queue_config_from_consumer_key!(consumer_key)['retry_gap'].present?
239
+ end
240
+
237
241
  def channel_pool_size(consumer_key)
238
242
  channel = channel_config(consumer_key)
239
243
  return data['channel_pool_size'] || 1 if channel.nil?
@@ -0,0 +1,27 @@
1
+ module Istox
2
+ class Formatter
3
+ class << self
4
+ include ActionView::Helpers::NumberHelper
5
+
6
+ # format a number, eg. 20000.134 > 20,000.14
7
+ def number(input, round_mode: :up, precision: 2)
8
+ BigDecimal.mode(BigDecimal::ROUND_MODE, round_mode)
9
+
10
+ input = 0 if input.blank?
11
+
12
+ input = ::BigDecimal.new(input.to_s).round(precision, round_mode)
13
+
14
+ number_with_precision(input, precision: precision, delimiter: ',')
15
+ end
16
+
17
+ # format a money, eg. 20000.134 > SGD 20,000.14, position can be :front or :behind
18
+ def money(input, round_mode: :up, precision: 2, currency:, position: :front)
19
+ result = number(input, round_mode: round_mode, precision: precision)
20
+
21
+ return currency + ' ' + result if position == :front
22
+
23
+ result + ' ' + currency
24
+ end
25
+ end
26
+ end
27
+ end
@@ -15,6 +15,10 @@ module Istox
15
15
  @interceptors.push(interceptor)
16
16
  end
17
17
 
18
+ def configure_grpc_logger
19
+ Gruf.grpc_logger = log
20
+ end
21
+
18
22
  def call(host_type, service, method, grpc_retries_count: 1, **keyword_args)
19
23
  execute(host_type, service, method, **keyword_args)
20
24
  rescue Gruf::Client::Errors::Unavailable => e
@@ -6,7 +6,7 @@ module Istox
6
6
  return @logger if @logger.present?
7
7
 
8
8
  @logger = ::Ougai::Logger.new(STDOUT)
9
- @logger.formatter = ::Ougai::Formatters::Readable.new unless Rails.env.production?
9
+ @logger.formatter = ::Ougai::Formatters::Readable.new unless ENV.fetch('RAILS_ENV','development') == 'production'|| (defined?(Rails) && Rails.env.production?)
10
10
 
11
11
  @logger
12
12
  end
@@ -78,6 +78,9 @@ module Istox
78
78
  @channel[t]['confirm-1'].close
79
79
  @channel[t]['noconfirm'].close
80
80
  @channel.delete t
81
+
82
+ # Remove exchange from @exchange
83
+ @exchanges.delete t
81
84
  end
82
85
  end
83
86
  end.join
@@ -233,7 +236,16 @@ module Istox
233
236
  sleep 1
234
237
  do_publish(ex,options,message)
235
238
  rescue => e
236
- log.debug "Error happens: #{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
249
  end
238
250
  end
239
251
  end
@@ -16,9 +16,9 @@ module Istox
16
16
  log.debug "Writing data to cache, key: #{key}, fields: #{fields.inspect}"
17
17
  log.debug "Cache data: #{data.inspect}"
18
18
 
19
- Thread.new do
20
- data = data.to_json unless data.instance_of?(String)
19
+ data = data.to_json unless data.instance_of?(String)
21
20
 
21
+ Thread.new do
22
22
  results = fields.map do |f|
23
23
  redis.hset(key, f.to_s, data)
24
24
  end
@@ -1,3 +1,4 @@
1
+ require 'exponential_backoff'
1
2
  require 'istox/helpers/logger'
2
3
 
3
4
  module Istox
@@ -79,26 +80,6 @@ module Istox
79
80
  queue.bind exchange, queue_options
80
81
  end
81
82
 
82
- if manual_ack
83
- letter_exchange = if exchange.nil?
84
- active_channel.default_exchange.name
85
- else
86
- exchange.name
87
- end
88
- retry_queue = active_channel.queue("#{queue_name}.retry", arguments: {
89
- 'x-dead-letter-exchange': letter_exchange,
90
- 'x-dead-letter-routing-key': queue_name.to_s,
91
- 'x-message-ttl': (::Istox::BunnyBoot.queue_retry_gap consumer_key)
92
- })
93
- if exchange_name.nil?
94
- exchange_retry = active_channel.default_exchange
95
- else
96
- exchange_retry_name = "#{exchange_name}.retry"
97
- exchange_retry = active_channel.send exchange_type, exchange_retry_name, durable: exchange_durable
98
- retry_queue.bind exchange_retry, routing_key: "#{queue_name}.retry" if manual_ack
99
- end
100
- end
101
-
102
83
  loop do
103
84
  break unless ::Istox::BunnyBoot.queue_single_consumer? consumer_key
104
85
 
@@ -115,9 +96,7 @@ module Istox
115
96
  ruby_class = ::Istox::BunnyBoot.ruby_class(consumer_key) || "#{consumer_key.to_s.underscore}_consumer"
116
97
  @workers = {} if @workers.nil?
117
98
  unless block || @workers[ruby_class]
118
- klass = Object.const_get(
119
- '::' + ruby_class.camelize
120
- )
99
+ klass = consumer_class(ruby_class)
121
100
  param = ::Istox::BunnyBoot.queue_worker_param consumer_key
122
101
  @workers[ruby_class] = if param.nil?
123
102
  klass.new
@@ -184,15 +163,13 @@ module Istox
184
163
  if ::Istox::BunnyBoot.queue_worker_param_format(consumer_key) == 'open_struct'
185
164
  processing_payload = ::Istox::CommonHelper.to_open_struct(processing_payload)
186
165
  end
187
- ::Istox::BunnyBoot.publish(exchange_retry, processing_payload, routing_key: "#{queue_name}.retry", priority: retry_count, type: 'dlx')
166
+
167
+ retry_obj = create_retry_obj(consumer_key, active_channel, exchange, exchange_name, queue_name, retry_count - 1)
168
+
169
+ ::Istox::BunnyBoot.publish(retry_obj.exchange_retry, processing_payload,
170
+ routing_key: retry_obj.routing_key, priority: retry_count, type: 'dlx')
188
171
  end
189
172
  end
190
- # # For redelivered message, call 'reject' not 'nack' in order to reschedule message to tail not head of queue
191
- # if delivery_info.redelivered
192
- # active_channel.reject(delivery_info.delivery_tag, true)
193
- # else
194
- # active_channel.nack(delivery_info.delivery_tag, false, true)
195
- # end
196
173
  ensure
197
174
  if manual_ack
198
175
  multiple = if !multiple.nil? && !result && result == multiple
@@ -205,6 +182,44 @@ module Istox
205
182
  end
206
183
  end
207
184
 
185
+ def create_retry_obj(consumer_key, active_channel, _exchange, exchange_name, queue_name, retried_count)
186
+ minimal_interval = 1.0
187
+ maximal_elapsed_time = 60.0
188
+
189
+ # retry interval will be [1, 3, 9, 27, 60, 60....] seconds
190
+ backoff = ExponentialBackoff.new(minimal_interval, maximal_elapsed_time)
191
+ backoff.multiplier = 3
192
+ ttl = ::Istox::BunnyBoot.queue_retry_gap_set?(consumer_key) ? ::Istox::BunnyBoot.queue_retry_gap(consumer_key) : backoff.interval_at(retried_count) * 1000
193
+ ttl = ttl.to_i
194
+
195
+ routing_key = "#{queue_name}.retry.#{ttl}"
196
+
197
+ retry_queue = active_channel.queue(routing_key, arguments: {
198
+ 'x-dead-letter-exchange': active_channel.default_exchange.name,
199
+ 'x-dead-letter-routing-key': queue_name.to_s,
200
+ 'x-message-ttl': ttl.to_i
201
+ })
202
+ if exchange_name.nil?
203
+ exchange_retry = active_channel.default_exchange
204
+ else
205
+ exchange_durable = ::Istox::BunnyBoot.exchange_durable? exchange_name
206
+ exchange_retry_name = "#{exchange_name}.retry"
207
+ exchange_retry = active_channel.direct(exchange_retry_name, durable: exchange_durable)
208
+ retry_queue.bind exchange_retry, routing_key: routing_key
209
+ end
210
+
211
+ OpenStruct.new(
212
+ exchange_retry: exchange_retry,
213
+ routing_key: routing_key
214
+ )
215
+ end
216
+
217
+ def consumer_class(ruby_class)
218
+ Object.const_get(
219
+ '::' + ruby_class.camelize
220
+ )
221
+ end
222
+
208
223
  def intercept(interceptors, payload, metadata, delivery_info)
209
224
  return yield if interceptors.none?
210
225
 
@@ -1,5 +1,4 @@
1
1
  require 'istox/helpers/logger'
2
- require 'aws-xray-sdk'
3
2
 
4
3
  module Istox
5
4
  module Xray
@@ -1,5 +1,4 @@
1
1
  require 'istox/helpers/logger'
2
- require 'aws-xray-sdk'
3
2
 
4
3
  module Istox
5
4
  module Xray
@@ -1,5 +1,4 @@
1
1
  require 'istox/helpers/logger'
2
- require 'aws-xray-sdk'
3
2
 
4
3
  module Istox
5
4
  module Xray
@@ -1,5 +1,4 @@
1
1
  require 'istox/helpers/logger'
2
- require 'aws-xray-sdk'
3
2
 
4
3
  module Istox
5
4
  module Xray
@@ -4,7 +4,6 @@ require 'istox/helpers/xray/grpc_server_xray_interceptor'
4
4
  require 'istox/helpers/xray/rabbitmq_publisher_interceptor'
5
5
  require 'istox/helpers/xray/rabbitmq_consumer_interceptor'
6
6
  require 'istox/helpers/logger'
7
- require 'aws-xray-sdk'
8
7
 
9
8
  module Istox
10
9
  module Xray
@@ -1,5 +1,4 @@
1
1
  require 'date'
2
- require 'rails'
3
2
 
4
3
  # https://en.wikipedia.org/wiki/Day_count_convention#30/360_Bond_Basis
5
4
  # For 360 basis: 30/360 Bond Basis
@@ -248,4 +247,4 @@ module Istox
248
247
 
249
248
  end
250
249
  end
251
- end
250
+ end
@@ -1,3 +1,3 @@
1
1
  module Istox
2
- VERSION = '0.1.153.4'.freeze
2
+ VERSION = '0.1.155'.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.153.4
4
+ version: 0.1.155
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-05-28 00:00:00.000000000 Z
11
+ date: 2020-07-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: amazing_print
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: 2.12.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: exponential-backoff
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 0.0.4
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 0.0.4
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: graphlient
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -332,6 +346,20 @@ dependencies:
332
346
  - - ">="
333
347
  - !ruby/object:Gem::Version
334
348
  version: '0'
349
+ - !ruby/object:Gem::Dependency
350
+ name: pry-byebug
351
+ requirement: !ruby/object:Gem::Requirement
352
+ requirements:
353
+ - - ">="
354
+ - !ruby/object:Gem::Version
355
+ version: '0'
356
+ type: :development
357
+ prerelease: false
358
+ version_requirements: !ruby/object:Gem::Requirement
359
+ requirements:
360
+ - - ">="
361
+ - !ruby/object:Gem::Version
362
+ version: '0'
335
363
  - !ruby/object:Gem::Dependency
336
364
  name: pry-rails
337
365
  requirement: !ruby/object:Gem::Requirement
@@ -455,6 +483,7 @@ files:
455
483
  - Rakefile
456
484
  - bin/console
457
485
  - bin/setup
486
+ - bulk-update-version.py
458
487
  - istox.gemspec
459
488
  - lib/istox.rb
460
489
  - lib/istox/constants/error.rb
@@ -464,6 +493,7 @@ files:
464
493
  - lib/istox/helpers/common_helper.rb
465
494
  - lib/istox/helpers/dlm.rb
466
495
  - lib/istox/helpers/f_math.rb
496
+ - lib/istox/helpers/formatter.rb
467
497
  - lib/istox/helpers/graphql_client.rb
468
498
  - lib/istox/helpers/grpc_client.rb
469
499
  - lib/istox/helpers/gruf_listener_hook.rb