istox 0.1.156.4 → 0.1.157.3

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.
@@ -1,9 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- istox (0.1.156.3)
4
+ istox (0.1.157)
5
5
  amazing_print
6
6
  awesome_print
7
+ aws-sdk-sns (~> 1)
7
8
  binding_of_caller
8
9
  bunny (>= 2.12.0)
9
10
  exponential-backoff (= 0.0.4)
@@ -63,8 +64,8 @@ GEM
63
64
  i18n (>= 0.7, < 2)
64
65
  minitest (~> 5.1)
65
66
  tzinfo (~> 1.1)
66
- amazing_print (1.2.0)
67
- amq-protocol (2.3.1)
67
+ amazing_print (1.2.1)
68
+ amq-protocol (2.3.2)
68
69
  arel (9.0.0)
69
70
  awesome_print (1.8.0)
70
71
  aws-eventstream (1.1.0)
@@ -74,6 +75,9 @@ GEM
74
75
  aws-partitions (~> 1, >= 1.239.0)
75
76
  aws-sigv4 (~> 1.1)
76
77
  jmespath (~> 1.0)
78
+ aws-sdk-sns (1.24.0)
79
+ aws-sdk-core (~> 3, >= 3.71.0)
80
+ aws-sigv4 (~> 1.1)
77
81
  aws-sdk-xray (1.4.0)
78
82
  aws-sdk-core (~> 3)
79
83
  aws-sigv4 (~> 1.0)
@@ -82,13 +86,14 @@ GEM
82
86
  aws-xray-sdk (0.11.4)
83
87
  aws-sdk-xray (~> 1.4.0)
84
88
  multi_json (~> 1)
89
+ bigdecimal (2.0.0)
85
90
  binding_of_caller (0.8.0)
86
91
  debug_inspector (>= 0.0.1)
87
92
  builder (3.2.4)
88
93
  bullet (5.7.6)
89
94
  activesupport (>= 3.0.0)
90
95
  uniform_notifier (~> 1.11.0)
91
- bunny (2.15.0)
96
+ bunny (2.16.1)
92
97
  amq-protocol (~> 2.3, >= 2.3.1)
93
98
  byebug (11.1.3)
94
99
  coderay (1.1.2)
@@ -115,21 +120,21 @@ GEM
115
120
  ffi (1.13.1)
116
121
  globalid (0.4.2)
117
122
  activesupport (>= 4.2.0)
118
- google-protobuf (3.12.2-universal-darwin)
123
+ google-protobuf (3.13.0-universal-darwin)
119
124
  googleapis-common-protos-types (1.0.5)
120
125
  google-protobuf (~> 3.11)
121
126
  graphlient (0.4.0)
122
127
  faraday (>= 1.0)
123
128
  faraday_middleware
124
129
  graphql-client
125
- graphql (1.10.10)
130
+ graphql (1.11.3)
126
131
  graphql-client (0.16.0)
127
132
  activesupport (>= 3.0)
128
133
  graphql (~> 1.8)
129
- grpc (1.28.0-universal-darwin)
130
- google-protobuf (~> 3.11)
134
+ grpc (1.31.1-universal-darwin)
135
+ google-protobuf (~> 3.12)
131
136
  googleapis-common-protos-types (~> 1.0)
132
- grpc-tools (1.28.0)
137
+ grpc-tools (1.31.1)
133
138
  gruf (2.8.1)
134
139
  activesupport (> 4)
135
140
  concurrent-ruby (> 1)
@@ -166,7 +171,8 @@ GEM
166
171
  nio4r (2.3.1)
167
172
  nokogiri (1.10.9)
168
173
  mini_portile2 (~> 2.4.0)
169
- oj (3.10.6)
174
+ oj (3.10.9)
175
+ bigdecimal (~> 2.0)
170
176
  ougai (1.8.5)
171
177
  oj (~> 3.10)
172
178
  paranoia (2.4.2)
@@ -218,16 +224,16 @@ GEM
218
224
  redis-activesupport (5.2.0)
219
225
  activesupport (>= 3, < 7)
220
226
  redis-store (>= 1.3, < 2)
221
- redis-namespace (1.7.0)
227
+ redis-namespace (1.8.0)
222
228
  redis (>= 3.0.4)
223
- redis-rack (2.1.2)
229
+ redis-rack (2.1.3)
224
230
  rack (>= 2.0.8, < 3)
225
231
  redis-store (>= 1.2, < 2)
226
232
  redis-rails (5.0.2)
227
233
  redis-actionpack (>= 5.0, < 6)
228
234
  redis-activesupport (>= 5.0, < 6)
229
235
  redis-store (>= 1.2, < 2)
230
- redis-store (1.8.2)
236
+ redis-store (1.9.0)
231
237
  redis (>= 4, < 5)
232
238
  rspec (3.8.0)
233
239
  rspec-core (~> 3.8.0)
@@ -250,7 +256,7 @@ GEM
250
256
  rspec-mocks (~> 3.8.0)
251
257
  rspec-support (~> 3.8.0)
252
258
  rspec-support (3.8.0)
253
- slop (4.8.1)
259
+ slop (4.8.2)
254
260
  sprockets (3.7.2)
255
261
  concurrent-ruby (~> 1.0)
256
262
  rack (> 1, < 3)
@@ -265,7 +271,7 @@ GEM
265
271
  tzinfo (1.2.6)
266
272
  thread_safe (~> 0.1)
267
273
  uniform_notifier (1.11.0)
268
- vault (0.14.0)
274
+ vault (0.15.0)
269
275
  aws-sigv4
270
276
  websocket-driver (0.7.0)
271
277
  websocket-extensions (>= 0.1.0)
@@ -32,6 +32,7 @@ Gem::Specification.new do |spec|
32
32
 
33
33
  spec.add_dependency 'amazing_print'
34
34
  spec.add_dependency 'awesome_print'
35
+ spec.add_dependency 'aws-sdk-sns', '~> 1'
35
36
  spec.add_dependency 'binding_of_caller'
36
37
  spec.add_dependency 'bunny', '>= 2.12.0'
37
38
  spec.add_dependency 'exponential-backoff', '0.0.4'
@@ -16,6 +16,7 @@ module Istox
16
16
  require 'istox/helpers/logger'
17
17
  require 'istox/interfaces/chainhub/transaction'
18
18
  require 'istox/helpers/publisher'
19
+ require 'istox/helpers/sns_publisher'
19
20
  require 'istox/helpers/subscriber'
20
21
  require 'istox/helpers/bunny_boot'
21
22
  require 'istox/helpers/rate_limit'
@@ -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"
@@ -139,8 +139,8 @@ module Istox
139
139
  name = queue_config_from_consumer_key!(consumer_key)['queue_name']
140
140
  return name if name.nil?
141
141
 
142
- prefix = queue_config_from_consumer_key!(consumer_key)['queue_prefix']
143
- suffix = queue_config_from_consumer_key!(consumer_key)['queue_suffix']
142
+ prefix = queue_config_from_consumer_key!(consumer_key, true)['queue_prefix']
143
+ suffix = queue_config_from_consumer_key!(consumer_key, true)['queue_suffix']
144
144
  delimiter = queue_config_from_consumer_key!(consumer_key)['queue_delimiter'] || '' unless prefix.nil? && suffix.nil?
145
145
 
146
146
  name = "#{prefix}#{delimiter}#{name}" unless prefix.nil?
@@ -157,7 +157,7 @@ module Istox
157
157
  end
158
158
 
159
159
  def queue_worker_param(consumer_key)
160
- queue_config_from_consumer_key!(consumer_key)['worker_param']
160
+ queue_config_from_consumer_key!(consumer_key, true)['worker_param']
161
161
  rescue StandardError
162
162
  nil
163
163
  end
@@ -365,17 +365,21 @@ module Istox
365
365
 
366
366
  private
367
367
 
368
- def data
368
+ def data(load_from_disk = false)
369
369
  Hashie.logger.level = 'ERROR'
370
- @data = Hashie::Mash.new(
371
- YAML.safe_load(
372
- ERB.new(File.read(ENV['AMQP_CONFIG'] || 'config/amqp.yml')).result
370
+ if load_from_disk || @data.nil?
371
+ @data = Hashie::Mash.new(
372
+ YAML.safe_load(
373
+ ERB.new(File.read(ENV['AMQP_CONFIG'] || 'config/amqp.yml')).result
374
+ )
373
375
  )
374
- )
376
+ end
377
+
378
+ @data
375
379
  end
376
380
 
377
- def queue_config_from_consumer_key!(consumer_key)
378
- queue_config = data['queues'][consumer_key]
381
+ def queue_config_from_consumer_key!(consumer_key, load_from_disk = false)
382
+ queue_config = data(load_from_disk)['queues'][consumer_key]
379
383
 
380
384
  raise "Queue for key #{consumer_key} config not found, have you forgotten to define the queue in amqp.yml?" if queue_config.nil?
381
385
 
@@ -8,6 +8,12 @@ module Istox
8
8
  @logger = ::Ougai::Logger.new(STDOUT)
9
9
  @logger.formatter = ::Ougai::Formatters::Readable.new unless ENV.fetch('RAILS_ENV','development') == 'production'|| (defined?(Rails) && Rails.env.production?)
10
10
 
11
+ # adding thread id to logger
12
+ @logger.before_log = lambda do |data|
13
+ data[:tracer_id] = Thread.current[:tracer_id]
14
+ data[:thread_id] = Thread.current.object_id
15
+ end
16
+
11
17
  @logger
12
18
  end
13
19
  end
@@ -0,0 +1,38 @@
1
+ require 'aws-sdk-sns'
2
+
3
+ module Istox
4
+ class SnsPublisher
5
+ class << self
6
+ # exception will not be thrown if throw_exception is set to false, exception will only be printed out and swallowed
7
+ def publish(message, topic_arn: nil, throw_exception: false)
8
+ if message.nil?
9
+ log.info('No message to publish, skipping SNS publish now...')
10
+ return
11
+ end
12
+
13
+ log.info('Publishing to SNS...')
14
+
15
+ message = JSON.generate(message) unless message.is_a? String
16
+
17
+ sns_client.publish({ topic_arn: topic_arn || ENV.fetch('PUSHER_TOPIC_ARN', ''), message: message })
18
+
19
+ log.info('Publish to SNS successfully.')
20
+ rescue StandardError => e
21
+ log.fatal 'Unable to publish SNS message.'
22
+ log.fatal(e)
23
+ log.info('Failed to publish SNS, ignoring...') unless throw_exception
24
+
25
+ raise e if throw_exception
26
+ end
27
+
28
+ def sns_client
29
+ return @sns_client if @sns_client.present?
30
+
31
+ Aws.config.update({ region: ENV.fetch('AWS_REGION', 'ap-southeast-1'),
32
+ credentials: Aws::Credentials.new(ENV.fetch('AWS_STS_ACCESS_KEY_ID'), ENV.fetch('AWS_STS_SECRET_ACCESS_KEY')) })
33
+
34
+ @sns_client = Aws::SNS::Client.new(region: ENV.fetch('AWS_REGION', 'ap-southeast-1'))
35
+ end
36
+ end
37
+ end
38
+ end
@@ -1,3 +1,3 @@
1
1
  module Istox
2
- VERSION = '0.1.156.4'.freeze
2
+ VERSION = '0.1.157.3'.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.156.4
4
+ version: 0.1.157.3
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-07-28 00:00:00.000000000 Z
11
+ date: 2020-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: amazing_print
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: aws-sdk-sns
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: binding_of_caller
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -509,6 +523,7 @@ files:
509
523
  - lib/istox/helpers/regex_helper.rb
510
524
  - lib/istox/helpers/remote_model_cache.rb
511
525
  - lib/istox/helpers/result_handler.rb
526
+ - lib/istox/helpers/sns_publisher.rb
512
527
  - lib/istox/helpers/subscriber.rb
513
528
  - lib/istox/helpers/vault.rb
514
529
  - lib/istox/helpers/xray/grpc_client_xray_interceptor.rb
@@ -524,7 +539,7 @@ files:
524
539
  homepage: http://www.abc.com
525
540
  licenses: []
526
541
  metadata: {}
527
- post_install_message:
542
+ post_install_message:
528
543
  rdoc_options: []
529
544
  require_paths:
530
545
  - lib
@@ -539,8 +554,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
539
554
  - !ruby/object:Gem::Version
540
555
  version: '0'
541
556
  requirements: []
542
- rubygems_version: 3.0.6
543
- signing_key:
557
+ rubygems_version: 3.0.8
558
+ signing_key:
544
559
  specification_version: 4
545
560
  summary: istox backend shared gem
546
561
  test_files: []