Class: Legion::Transport::Messages::Task

Inherits:
Legion::Transport::Message show all
Defined in:
lib/legion/transport/messages/task.rb

Constant Summary

Constants inherited from Legion::Transport::Message

Legion::Transport::Message::ENVELOPE_KEYS

Constants included from Common

Common::NAMESPACE_BOUNDARIES

Instance Method Summary collapse

Methods inherited from Legion::Transport::Message

#app_id, #channel, #content_encoding, #content_type, #correlation_id, #encode_message, #encrypt?, #encrypt_message, #exchange_name, #expiration, #headers, #initialize, max_payload_bytes, #message_id, #persistent, #priority, #publish, #reply_to, #timestamp, #type, #user_id

Methods included from Common

#channel, #channel_open?, #close, #close!, #deep_merge, #generate_consumer_tag, #open_channel, #options_builder

Constructor Details

This class inherits a constructor from Legion::Transport::Message

Instance Method Details

#exchangeObject



7
8
9
10
11
12
13
# File 'lib/legion/transport/messages/task.rb', line 7

def exchange
  if @options.key?(:exchange) && @options[:exchange].is_a?(String)
    Legion::Transport::Exchange.new(@options[:exchange])
  else
    Legion::Transport::Exchanges::Task.new
  end
end

#messageObject



15
16
17
# File 'lib/legion/transport/messages/task.rb', line 15

def message
  @options
end

#routing_keyObject



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/legion/transport/messages/task.rb', line 19

def routing_key
  key = if @options.key? :routing_key
          @options[:routing_key]
        elsif @options[:conditions].is_a?(String) && @options[:conditions].length > 2
          'task.subtask.conditioner'
        elsif @options[:transformation].is_a?(String) && @options[:transformation].length > 2
          'task.subtask.transform'
        elsif @options[:queue].is_a?(String) && @options[:function].is_a?(String)
          "#{@options[:queue]}.#{@options[:function]}"
        end
  log.debug "Task routing_key=#{key}"
  key
end

#validateObject

Raises:

  • (TypeError)


33
34
35
36
37
# File 'lib/legion/transport/messages/task.rb', line 33

def validate
  raise TypeError unless @options[:function].is_a? String

  @valid = true
end