istox 0.1.156 → 0.1.156.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.idea/istox-gem.iml +2 -1852
- data/Gemfile.lock +1 -1
- data/bulk-update-version.py +2 -1
- data/lib/istox/consumers/blockchain_status_handler.rb +1 -1
- data/lib/istox/helpers/bunny_boot.rb +4 -0
- data/lib/istox/helpers/formatter.rb +9 -7
- data/lib/istox/helpers/publisher.rb +32 -22
- data/lib/istox/version.rb +1 -1
- metadata +6 -6
data/Gemfile.lock
CHANGED
data/bulk-update-version.py
CHANGED
@@ -7,7 +7,8 @@ import os
|
|
7
7
|
|
8
8
|
# HOW TO RUN: python bulk-update-version.py <version updating to, eg. 0.1.150.2>
|
9
9
|
|
10
|
-
SERVICES = ["client-api", "admin-api", "message-api",
|
10
|
+
SERVICES = ["client-api", "admin-api", "message-api",
|
11
|
+
"auth", "admin-auth", "banking-api", "trading-api"]
|
11
12
|
|
12
13
|
|
13
14
|
def replace(file_path, pattern, subst):
|
@@ -88,7 +88,7 @@ module Istox
|
|
88
88
|
end
|
89
89
|
|
90
90
|
def mark_resource_handled(receipt)
|
91
|
-
receipt.update(resource_handled: true)
|
91
|
+
receipt.reload.update(resource_handled: true)
|
92
92
|
rescue StandardError => e
|
93
93
|
log.warn "Unable to update resource_handled for receipt #{receipt.inspect},
|
94
94
|
but will silently ignore the error"
|
@@ -276,6 +276,10 @@ module Istox
|
|
276
276
|
end
|
277
277
|
options_dup.merge!(persistent: persistent)
|
278
278
|
options_dup.merge!(mandatory: mandatory)
|
279
|
+
|
280
|
+
options_dup[:headers] = {} if options[:headers].nil?
|
281
|
+
options_dup[:headers][:sender] = Thread.current.object_id
|
282
|
+
|
279
283
|
# message.merge!(locale: I18n.locale)
|
280
284
|
|
281
285
|
publisher_interceptors.each do |interceptor|
|
@@ -1,22 +1,24 @@
|
|
1
1
|
module Istox
|
2
2
|
class Formatter
|
3
3
|
class << self
|
4
|
-
include ActionView::Helpers::NumberHelper
|
5
|
-
|
6
4
|
# format a number, eg. 20000.134 > 20,000.14
|
7
|
-
def number(input, round_mode: :half_up, precision: 2)
|
5
|
+
def number(input, round_mode: :half_up, precision: 2, abs_num: false)
|
8
6
|
BigDecimal.mode(BigDecimal::ROUND_MODE, round_mode)
|
9
7
|
|
10
8
|
input = 0 if input.blank?
|
11
9
|
|
12
10
|
input = ::BigDecimal.new(input.to_s).round(precision, round_mode)
|
13
11
|
|
14
|
-
|
12
|
+
input = input.abs if abs_num
|
13
|
+
|
14
|
+
result = format("%.#{precision}f", input)
|
15
|
+
|
16
|
+
result.to_s.reverse.gsub(/(\d{3})(?=\d)/, '\\1,').reverse
|
15
17
|
end
|
16
18
|
|
17
|
-
# format a money, eg. 20000.134 > SGD 20,000.14, position can be :front or :behind
|
18
|
-
def money(input, round_mode: :half_up, precision: 2, currency:, position: :front)
|
19
|
-
result = number(input, round_mode: round_mode, precision: precision)
|
19
|
+
# format a money, eg. 20000.134 > SGD 20,000.14, position can be :front or :behind, abs_num: whether to absolute the number
|
20
|
+
def money(input, round_mode: :half_up, precision: 2, currency:, position: :front, abs_num: false)
|
21
|
+
result = number(input, round_mode: round_mode, precision: precision, abs_num: abs_num)
|
20
22
|
|
21
23
|
return currency + ' ' + result if position == :front
|
22
24
|
|
@@ -1,6 +1,9 @@
|
|
1
1
|
require 'securerandom'
|
2
2
|
require 'istox/helpers/logger'
|
3
3
|
|
4
|
+
class RabbitMQPublishError < StandardError
|
5
|
+
end
|
6
|
+
|
4
7
|
module Istox
|
5
8
|
# Publisher is relying on BunnyBoot to publish message, please make sure BunnyBoot is initalised properly first during runtime.
|
6
9
|
class Publisher
|
@@ -174,21 +177,20 @@ module Istox
|
|
174
177
|
# when an unroutable message is returned, the BasicReturn is fired first and then an ack is sent, firing the BasicAck second.
|
175
178
|
# So if the current status is unroutable then we need to make sure that we don't overwrite that status with Success (ack).
|
176
179
|
ex.on_return do |return_info, properties, content|
|
177
|
-
return_info = return_info.to_hash
|
178
|
-
properties = properties.to_hash
|
180
|
+
return_info = return_info.to_hash.deep_symbolize_keys
|
181
|
+
properties = properties.to_hash.deep_symbolize_keys
|
179
182
|
log.debug "Got a returned message info: #{return_info}"
|
180
183
|
log.debug "Got a returned message properties: #{properties}"
|
181
184
|
log.debug "Got a returned message content: #{content}"
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
185
|
+
|
186
|
+
if properties[:headers] && properties[:headers][:sender]
|
187
|
+
@error = Hash.new if @error.nil?
|
188
|
+
tid = properties[:headers][:sender]
|
189
|
+
@error[tid] = Hash.new if @error[Thread.current.object_id].nil?
|
190
|
+
@error[tid][:return_info] = return_info
|
191
|
+
@error[tid][:properties] = properties
|
192
|
+
@error[tid][:content] = content
|
187
193
|
end
|
188
|
-
=end
|
189
|
-
options = properties.clone
|
190
|
-
options[:routing_key] = return_info[:routing_key]
|
191
|
-
republish(ex, options, content)
|
192
194
|
end
|
193
195
|
|
194
196
|
exchanges[id] = ex
|
@@ -199,7 +201,7 @@ module Istox
|
|
199
201
|
end
|
200
202
|
|
201
203
|
# Handle republish: check and increase retry count
|
202
|
-
def republish(ex, options = {}, message)
|
204
|
+
def republish(ex, options = {}, message, error)
|
203
205
|
options[:headers] = {} if options[:headers].nil?
|
204
206
|
|
205
207
|
if options[:headers][:republish].nil?
|
@@ -208,11 +210,12 @@ module Istox
|
|
208
210
|
else
|
209
211
|
options[:headers][:republish_count] += 1
|
210
212
|
if options[:headers][:republish_count] > 10
|
211
|
-
log.
|
213
|
+
log.fatal "Already retry to publish for 10 times, and give up retry"
|
212
214
|
log.info "Publish options: #{options.inspect}"
|
213
215
|
log.info "Publish to exchange: #{ex.name}"
|
214
216
|
log.info "Publish payload: #{message.inspect}"
|
215
|
-
|
217
|
+
|
218
|
+
raise RabbitMQPublishError, "Publish fails after retries(10): #{error}"
|
216
219
|
end
|
217
220
|
end
|
218
221
|
|
@@ -245,27 +248,34 @@ module Istox
|
|
245
248
|
success = ex.channel.wait_for_confirms
|
246
249
|
if success
|
247
250
|
log.debug("Message confirm success: remove message for #{channel_id}")
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
+
if @error.nil? || @error[Thread.current.object_id].nil?
|
252
|
+
# republish(ex, options, message, 'simulate errors')
|
253
|
+
true
|
254
|
+
else
|
255
|
+
error = @error[Thread.current.object_id][:return_info][:reply_text]
|
256
|
+
@error[Thread.current.object_id] = nil
|
257
|
+
republish(ex, options, message, error)
|
258
|
+
end
|
251
259
|
else
|
252
260
|
ex.channel.nacked_set.each do |n|
|
253
261
|
log.debug("Publish Error: UNACK delivery tag is #{n}, republish message")
|
254
262
|
# options = ::Istox::BunnyBoot.find_tracker_on_channel(channel_id, n, 'options')
|
255
263
|
# options = JSON.parse(options, :symbolize_names => true)
|
256
264
|
# options[:delivery_tag] = n
|
257
|
-
republish(ex, options, message)
|
265
|
+
republish(ex, options, message, 'broker processing fails')
|
258
266
|
end
|
259
267
|
end
|
260
268
|
end
|
261
269
|
rescue Bunny::ConnectionClosedError => e
|
262
|
-
log.
|
270
|
+
log.error "Publish fails due to #{e}"
|
263
271
|
# For network related retry, sleep 2 second before retry
|
264
272
|
# Because it may take some seconds for automatic recovery of network
|
265
273
|
sleep 2
|
266
|
-
republish(ex,options,message)
|
274
|
+
republish(ex, options, message, e.message)
|
275
|
+
rescue RabbitMQPublishError => e
|
276
|
+
raise RabbitMQPublishError, e.message
|
267
277
|
rescue => e
|
268
|
-
log.
|
278
|
+
log.error "Publish error happening: #{e.message}"
|
269
279
|
|
270
280
|
# If the error indicates that the channel is already closed
|
271
281
|
# then clear hash @channel and @exchange
|
@@ -277,7 +287,7 @@ module Istox
|
|
277
287
|
end
|
278
288
|
|
279
289
|
# Republish msg
|
280
|
-
republish(ex, options, message)
|
290
|
+
republish(ex, options, message, e.message)
|
281
291
|
end
|
282
292
|
end
|
283
293
|
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.1.156
|
4
|
+
version: 0.1.156.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Siong Leng
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-08-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: amazing_print
|
@@ -524,7 +524,7 @@ files:
|
|
524
524
|
homepage: http://www.abc.com
|
525
525
|
licenses: []
|
526
526
|
metadata: {}
|
527
|
-
post_install_message:
|
527
|
+
post_install_message:
|
528
528
|
rdoc_options: []
|
529
529
|
require_paths:
|
530
530
|
- lib
|
@@ -539,8 +539,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
539
539
|
- !ruby/object:Gem::Version
|
540
540
|
version: '0'
|
541
541
|
requirements: []
|
542
|
-
rubygems_version: 3.0.
|
543
|
-
signing_key:
|
542
|
+
rubygems_version: 3.0.6
|
543
|
+
signing_key:
|
544
544
|
specification_version: 4
|
545
545
|
summary: istox backend shared gem
|
546
546
|
test_files: []
|