legion-transport 1.1.3 → 1.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aca9d21a2d161f0838dc16ce328d81c3ba42360a777c63e6aa805f6c52502e13
4
- data.tar.gz: 46af9353894537c81d73a68e01522498181d6d2fb54ae3fcdec465ebb75f8675
3
+ metadata.gz: a14303eeb59f5d328dba4782a6fcab96087a63403fa7e734fa98738c6010fccd
4
+ data.tar.gz: 3c30d91267de37a9f04e721755dd5452a9dcb8c6ff649c9a17ce0b941893be5d
5
5
  SHA512:
6
- metadata.gz: add6818532d2159f4fa2be2a40148694f24511f7ca5095ad4477c9e0b72d70c546b2c7ba7ce6b60b44fa9b538c64e08d032dede1f341bbcb6e1831f541828d0e
7
- data.tar.gz: 754b708ce889ff36ab763f4f72887895195721a9f5e43bea168e802ad6cde0e3fc813ef9ed7ac2e11d677388777d264fc635b57912376f96dff1b03d71108ce3
6
+ metadata.gz: b4e78c019c6ae475aa18cb82108c024d9df78f84d46073cdfcbbffafc2b1ac393e255052f4036a3311f652f01269aa1cfe7e636b6153c30b0c32cf11825e4622
7
+ data.tar.gz: f42031b318d1e491fff023496c379c323e8ec81aebe750d0291b8bdf0b6c1f361fd99b0d60804ba0814023b560f2e6ca3c76c00e845472cbf60ba54a9fbdc97e
@@ -3,11 +3,11 @@ require_relative 'transport/settings'
3
3
 
4
4
  module Legion
5
5
  module Transport
6
- if RUBY_ENGINE == 'jruby' && defined?(::Marchhare)
7
- require 'marchhare'
8
- TYPE = 'marchhare'.freeze
9
- CONNECTOR = ::Marchhare
10
- else
6
+ begin
7
+ require 'march_hare'
8
+ TYPE = 'march_hare'.freeze
9
+ CONNECTOR = ::MarchHare
10
+ rescue LoadError
11
11
  require 'bunny'
12
12
  TYPE = 'bunny'.freeze
13
13
  CONNECTOR = ::Bunny
@@ -17,6 +17,5 @@ module Legion
17
17
  require_relative 'transport/common'
18
18
  require_relative 'transport/queue'
19
19
  require_relative 'transport/exchange'
20
- require_relative 'transport/consumer'
21
20
  require_relative 'transport/message'
22
21
  end
@@ -8,11 +8,24 @@ module Legion
8
8
  Legion::Transport::CONNECTOR
9
9
  end
10
10
 
11
- def setup # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
11
+ def setup # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity,Metrics/MethodLength
12
+ Legion::Logging.info("Using transport connector: #{Legion::Transport::CONNECTOR}")
13
+
12
14
  if @session.respond_to?(:value) && session.respond_to?(:closed?) && session.closed?
13
- @channel_thread = Concurrent::ThreadLocalVar.new
15
+ @channel_thread = Concurrent::ThreadLocalVar.new(nil)
14
16
  elsif @session.respond_to?(:value) && session.respond_to?(:closed?) && session.open?
15
- return nil
17
+ nil
18
+ elsif Legion::Transport::TYPE == 'march_hare'
19
+ @session ||= Concurrent::Atom.new(
20
+ MarchHare.connect(host: Legion::Settings[:transport][:connection][:host],
21
+ vhost: Legion::Settings[:transport][:connection][:vhost],
22
+ user: Legion::Settings[:transport][:connection][:user],
23
+ password: Legion::Settings[:transport][:connection][:password],
24
+ port: Legion::Settings[:transport][:connection][:port])
25
+ )
26
+ @channel_thread = Concurrent::ThreadLocalVar.new(nil)
27
+ session.start
28
+ session.create_channel.basic_qos(1)
16
29
  else
17
30
  @session ||= Concurrent::Atom.new(
18
31
  connector.new(
@@ -21,18 +34,35 @@ module Legion
21
34
  log_level: :info
22
35
  )
23
36
  )
24
- @channel_thread = Concurrent::ThreadLocalVar.new
37
+ @channel_thread = Concurrent::ThreadLocalVar.new(nil)
38
+ session.start
39
+ session.create_channel.basic_qos(20, true)
25
40
  end
26
41
 
27
- session.start
28
- session.create_channel.basic_qos(1, true)
42
+ if session.respond_to? :on_blocked
43
+ session.on_blocked { Legion::Logging.warn('Legion::Transport is being blocked by RabbitMQ!') }
44
+ end
45
+
46
+ if session.respond_to? :on_unblocked
47
+ session.on_unblocked { Legion::Logging.info('Legion::Transport is no longer being blocked by RabbitMQ') }
48
+ end
49
+
50
+ if session.respond_to? :after_recovery_completed
51
+ session.after_recovery_completed { Legion::Logging.info('Legion::Transport has completed recovery') }
52
+ end
53
+
54
+ true
29
55
  end
30
56
 
31
- def channel
57
+ def channel # rubocop:disable Metrics/AbcSize
32
58
  return @channel_thread.value if !@channel_thread.value.nil? && @channel_thread.value.open?
33
59
 
34
60
  @channel_thread.value = session.create_channel
35
- @channel_thread.value.prefetch(Legion::Settings[:transport][:prefetch])
61
+ if Legion::Transport::TYPE == 'march_hare'
62
+ @channel_thread.value.basic_qos(Legion::Settings[:transport][:prefetch])
63
+ else
64
+ @channel_thread.value.prefetch(Legion::Settings[:transport][:prefetch])
65
+ end
36
66
  @channel_thread.value
37
67
  end
38
68
 
@@ -6,8 +6,14 @@ module Legion
6
6
  def initialize(exchange = exchange_name, options = {})
7
7
  @options = options
8
8
  @type = options[:type] || default_type
9
- super(channel, @type, exchange, options_builder(default_options, exchange_options, @options))
10
- rescue ::Bunny::PreconditionFailed, ::Bunny::ChannelAlreadyClosed
9
+ if Legion::Transport::TYPE == 'march_hare'
10
+ super_options = options_builder(default_options, exchange_options, @options)
11
+ super_options[:type] = @type
12
+ super(channel, exchange, **super_options)
13
+ else
14
+ super(channel, @type, exchange, options_builder(default_options, exchange_options, @options))
15
+ end
16
+ rescue Legion::Transport::CONNECTOR::PreconditionFailed, Legion::Transport::CONNECTOR::ChannelAlreadyClosed
11
17
  raise unless @retries.nil?
12
18
 
13
19
  @retries = 1
@@ -39,7 +45,7 @@ module Legion
39
45
  def delete(options = {})
40
46
  super(options)
41
47
  true
42
- rescue ::Bunny::PreconditionFailed
48
+ rescue Legion::Transport::CONNECTOR::PreconditionFailed
43
49
  false
44
50
  end
45
51
 
@@ -11,7 +11,9 @@ module Legion
11
11
  def publish(options = @options) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
12
12
  raise unless @valid
13
13
 
14
- exchange_dest = exchange.respond_to?(:new) ? exchange.new : exchange
14
+ $exchanges = {} if $exchanges.nil?
15
+ $exchanges[exchange.to_s] = exchange.new unless $exchanges.key?(exchange.to_s)
16
+ exchange_dest = $exchanges[exchange.to_s]
15
17
  exchange_dest.publish(encode_message,
16
18
  routing_key: routing_key || '',
17
19
  content_type: options[:content_type] || content_type,
@@ -26,6 +28,10 @@ module Legion
26
28
  @options
27
29
  end
28
30
 
31
+ def routing_key
32
+ nil
33
+ end
34
+
29
35
  def encode_message
30
36
  message_payload = message
31
37
  message_payload = Legion::JSON.dump(message_payload) unless message_payload.is_a? String
@@ -16,17 +16,6 @@ module Legion
16
16
  }
17
17
  end
18
18
 
19
- def routing_key # rubocop:disable Metrics/AbcSize
20
- if @options[:conditions].is_a?(String) && @options[:conditions].length > 2
21
- 'task.subtask.conditioner'
22
- elsif @options[:transformation].is_a?(String) && @options[:transformation].length > 2
23
- 'task.subtask.transform'
24
- elsif @options[:function_id].is_a? Integer
25
- function = Legion::Data::Model::Function[@options[:function_id]]
26
- "#{function.runner.extension.values[:exchange]}.#{function.runner.values[:queue]}.#{function.values[:name]}"
27
- end
28
- end
29
-
30
19
  def validate
31
20
  raise TypeError unless @options[:function].is_a? String
32
21
 
@@ -7,7 +7,7 @@ module Legion
7
7
  retries ||= 0
8
8
  @options = options
9
9
  super(channel, queue, options_builder(default_options, queue_options, options))
10
- rescue ::Bunny::PreconditionFailed
10
+ rescue Legion::Transport::CONNECTOR::PreconditionFailed
11
11
  retries.zero? ? retries = 1 : raise
12
12
  recreate_queue(channel, queue)
13
13
  retry
@@ -51,7 +51,7 @@ module Legion
51
51
  def delete(options = { if_unused: true, if_empty: true })
52
52
  super(options)
53
53
  true
54
- rescue ::Bunny::PreconditionFailed
54
+ rescue Legion::Transport::CONNECTOR::PreconditionFailed
55
55
  false
56
56
  end
57
57
 
@@ -16,7 +16,7 @@ module Legion
16
16
  password: 'guest',
17
17
  host: '127.0.0.1',
18
18
  port: '5672',
19
- vhost: '/',
19
+ vhost: 'legion',
20
20
  recovery_attempts: 0,
21
21
  logger_level: 'info'
22
22
  }.merge(grab_vault_creds)
@@ -1,5 +1,5 @@
1
1
  module Legion
2
2
  module Transport
3
- VERSION = '1.1.3'.freeze
3
+ VERSION = '1.1.4'.freeze
4
4
  end
5
5
  end
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "transport": {
3
- "vhost": "/"
3
+ "vhost": "legion"
4
4
  }
5
5
  }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: legion-transport
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Esity
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-25 00:00:00.000000000 Z
11
+ date: 2020-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler