istox 0.1.157 → 0.1.157.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- istox (0.1.157)
4
+ istox (0.1.157.5)
5
5
  amazing_print
6
6
  awesome_print
7
7
  aws-sdk-sns (~> 1)
@@ -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
@@ -29,7 +29,7 @@ module Istox
29
29
  return @sns_client if @sns_client.present?
30
30
 
31
31
  Aws.config.update({ region: ENV.fetch('AWS_REGION', 'ap-southeast-1'),
32
- credentials: Aws::Credentials.new('AWS_STS_ACCESS_KEY_ID', 'AWS_STS_SECRET_ACCESS_KEY') })
32
+ credentials: Aws::Credentials.new(ENV.fetch('AWS_STS_ACCESS_KEY_ID'), ENV.fetch('AWS_STS_SECRET_ACCESS_KEY')) })
33
33
 
34
34
  @sns_client = Aws::SNS::Client.new(region: ENV.fetch('AWS_REGION', 'ap-southeast-1'))
35
35
  end
@@ -51,13 +51,17 @@ 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)
59
63
  active_channel.queue_delete(queue_name)
60
- queue = active_channel.queue(queue_name, durable: queue_durable)
64
+ queue = active_channel.queue(queue_name, durable: queue_durable, arguments: arguments)
61
65
  end
62
66
 
63
67
  # Declare exchange
@@ -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.157'.freeze
2
+ VERSION = '0.1.157.5'.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.157
4
+ version: 0.1.157.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-08-20 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
@@ -539,7 +539,7 @@ files:
539
539
  homepage: http://www.abc.com
540
540
  licenses: []
541
541
  metadata: {}
542
- post_install_message:
542
+ post_install_message:
543
543
  rdoc_options: []
544
544
  require_paths:
545
545
  - lib
@@ -554,8 +554,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
554
554
  - !ruby/object:Gem::Version
555
555
  version: '0'
556
556
  requirements: []
557
- rubygems_version: 3.0.6
558
- signing_key:
557
+ rubygems_version: 3.0.8
558
+ signing_key:
559
559
  specification_version: 4
560
560
  summary: istox backend shared gem
561
561
  test_files: []