Module: Legion::Transport::Common
- Includes:
- Logging::Helper
- Defined in:
- lib/legion/transport/common.rb
Constant Summary collapse
- NAMESPACE_BOUNDARIES =
%w[Actor Actors Runners Helpers Transport Data Queues Queue Exchanges Exchange Messages Message].freeze
Instance Method Summary collapse
-
#channel ⇒ Object
rubocop:enable all.
- #channel_open? ⇒ Boolean
- #close ⇒ Object
- #close! ⇒ Object
-
#deep_merge(original, new) ⇒ Object
rubocop:disable all.
- #generate_consumer_tag(lex_name: nil, runner_name: nil, thread: Thread.current.object_id) ⇒ Object
- #open_channel(_options = {}) ⇒ Object
- #options_builder(first, *args) ⇒ Object
Instance Method Details
#channel ⇒ Object
rubocop:enable all
57 58 59 |
# File 'lib/legion/transport/common.rb', line 57 def channel @channel ||= Legion::Transport::Connection.channel end |
#channel_open? ⇒ Boolean
17 18 19 |
# File 'lib/legion/transport/common.rb', line 17 def channel_open? channel.open? end |
#close ⇒ Object
68 69 70 71 |
# File 'lib/legion/transport/common.rb', line 68 def close log.warn 'close called, but method is called close!' close! end |
#close! ⇒ Object
61 62 63 64 65 66 |
# File 'lib/legion/transport/common.rb', line 61 def close! log.info 'close! called' return false unless Legion::Transport::Connection.channel_open? Legion::Transport::Connection.channel.close end |
#deep_merge(original, new) ⇒ Object
rubocop:disable all
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/legion/transport/common.rb', line 34 def deep_merge(original, new) {} unless original.is_a?(Hash) && new.is_a?(Hash) original unless new.is_a? Hash new unless original.is_a? Hash new if original.nil? || original.empty? original if new.nil? || new.empty? new.each do |k, v| unless original.key?(k) original[k] = v next end original[k.to_sym] = if [original[k.to_sym], new[k.to_sym]].all? { |a| a.is_a? Hash } deep_merge(original[k], new[k]) else new[k] end end original end |
#generate_consumer_tag(lex_name: nil, runner_name: nil, thread: Thread.current.object_id) ⇒ Object
73 74 75 76 77 78 79 80 |
# File 'lib/legion/transport/common.rb', line 73 def generate_consumer_tag(lex_name: nil, runner_name: nil, thread: Thread.current.object_id) tag = "#{Legion::Settings[:client][:name]}_" tag.concat("#{lex_name}_") unless lex_name.nil? tag.concat("#{runner_name}_") unless runner_name.nil? tag.concat("#{thread}_") tag.concat(SecureRandom.hex) tag end |
#open_channel(_options = {}) ⇒ Object
13 14 15 |
# File 'lib/legion/transport/common.rb', line 13 def open_channel( = {}) @channel = Legion::Transport::Connection.channel end |
#options_builder(first, *args) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/legion/transport/common.rb', line 21 def (first, *args) = nil args.each do |option| = if .nil? deep_merge(first, option) else deep_merge(, option) end end end |