istox 0.1.156.5 → 0.1.157.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,9 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- istox (0.1.156.3)
4
+ istox (0.1.157.4)
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'
@@ -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
@@ -262,6 +262,7 @@ module Istox
262
262
  # For persistence, if exchange is durable, persistent is enabled
263
263
  # For mandatory. if channel is confirmed mode, mandatory is enabled
264
264
  persistent = e.durable?
265
+ persistent = true if eid(e) == :default
265
266
  mandatory = channel_confirm? e.channel
266
267
  options_dup = options.clone
267
268
 
@@ -365,17 +366,21 @@ module Istox
365
366
 
366
367
  private
367
368
 
368
- def data
369
+ def data(load_from_disk = false)
369
370
  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
371
+ if load_from_disk || @data.nil?
372
+ @data = Hashie::Mash.new(
373
+ YAML.safe_load(
374
+ ERB.new(File.read(ENV['AMQP_CONFIG'] || 'config/amqp.yml')).result
375
+ )
373
376
  )
374
- )
377
+ end
378
+
379
+ @data
375
380
  end
376
381
 
377
- def queue_config_from_consumer_key!(consumer_key)
378
- queue_config = data['queues'][consumer_key]
382
+ def queue_config_from_consumer_key!(consumer_key, load_from_disk = false)
383
+ queue_config = data(load_from_disk)['queues'][consumer_key]
379
384
 
380
385
  raise "Queue for key #{consumer_key} config not found, have you forgotten to define the queue in amqp.yml?" if queue_config.nil?
381
386
 
@@ -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
@@ -51,8 +51,12 @@ module Istox
51
51
  queue_name = ::Istox::BunnyBoot.queue_name consumer_key
52
52
  queue_durable = ::Istox::BunnyBoot.queue_durable? consumer_key
53
53
  queue_exclusive = ::Istox::BunnyBoot.queue_exclusive consumer_key
54
+ priority = ::Istox::BunnyBoot.queue_priority consumer_key
55
+ arguments = {}
56
+ arguments['x-max-priority'] = priority unless priority.nil?
57
+
54
58
  begin
55
- queue = active_channel.queue(queue_name, durable: queue_durable, exclusive: queue_exclusive || false)
59
+ queue = active_channel.queue(queue_name, durable: queue_durable, exclusive: queue_exclusive || false, arguments: arguments)
56
60
  rescue Bunny::PreconditionFailed => e
57
61
  # Must re-open a new channel, because now channel is already closed
58
62
  active_channel = ::Istox::BunnyBoot.channel(::Istox::BunnyBoot.connection, pool_size: pool_size, prefetch: prefetch)
@@ -105,10 +109,7 @@ module Istox
105
109
  end
106
110
  end
107
111
  # Subscribe queue
108
- priority = ::Istox::BunnyBoot.queue_priority consumer_key
109
- arguments = {}
110
- arguments['x-max-priority'] = priority unless priority.nil?
111
- queue.subscribe manual_ack: manual_ack, arguments: arguments do |delivery_info, metadata, payload|
112
+ queue.subscribe manual_ack: manual_ack do |delivery_info, metadata, payload|
112
113
  # For retried message, if reaching retry count limit, return ack anyway
113
114
  # If retry limit is -1, no retry limit
114
115
  # TODO: No matter the amount of retry limit, send cloudwatch critical alarm if fails after 3 times of retry
@@ -1,3 +1,3 @@
1
1
  module Istox
2
- VERSION = '0.1.156.5'.freeze
2
+ VERSION = '0.1.157.4'.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.5
4
+ version: 0.1.157.4
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-08-16 00:00:00.000000000 Z
11
+ date: 2020-09-10 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: []