Module: Legion::Transport::Common
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
52 53 54 |
# File 'lib/legion/transport/common.rb', line 52 def channel @channel ||= Legion::Transport::Connection.channel end |
#channel_open? ⇒ Boolean
12 13 14 |
# File 'lib/legion/transport/common.rb', line 12 def channel_open? channel.open? end |
#close ⇒ Object
63 64 65 66 67 |
# File 'lib/legion/transport/common.rb', line 63 def close Legion::Transport.logger.error 'close called' Legion::Transport.logger.warn 'close called, but method is called close!' close! end |
#close! ⇒ Object
56 57 58 59 60 61 |
# File 'lib/legion/transport/common.rb', line 56 def close! Legion::Transport.logger.error 'close! called' return false unless Legion::Transport::Connection.channel_open? Legion::Transport::Connection.channel.close end |
#deep_merge(original, new) ⇒ Object
rubocop:disable all
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/legion/transport/common.rb', line 29 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
69 70 71 72 73 74 75 76 |
# File 'lib/legion/transport/common.rb', line 69 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
8 9 10 |
# File 'lib/legion/transport/common.rb', line 8 def open_channel( = {}) @channel = Legion::Transport::Connection.channel end |
#options_builder(first, *args) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/legion/transport/common.rb', line 16 def (first, *args) = nil args.each do |option| = if .nil? deep_merge(first, option) else deep_merge(, option) end end end |