Class: Legion::Transport::Messages::SubTask

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

Constant Summary

Constants inherited from Legion::Transport::Message

Legion::Transport::Message::ENVELOPE_KEYS

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, #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



9
10
11
# File 'lib/legion/transport/messages/subtask.rb', line 9

def exchange
  Legion::Transport::Exchanges::Task
end

#messageObject



13
14
15
16
17
18
19
# File 'lib/legion/transport/messages/subtask.rb', line 13

def message
  {
    transformation: @options[:transformation] || '{}',
    conditions:     @options[:conditions] || '{}',
    results:        @options[:results] || '{}'
  }
end

#routing_keyObject



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

def routing_key
  key = if @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[:function_id].is_a? Integer
          function = Legion::Data::Model::Function[@options[:function_id]]
          "#{function.runner.extension.values[:exchange]}.#{function.runner.values[:queue]}.#{function.values[:name]}"
        end
  Legion::Logging.debug "SubTask routing_key=#{key} function_id=#{@options[:function_id]}" if defined?(Legion::Logging)
  key
end

#validateObject

Raises:

  • (TypeError)


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

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

  @valid = true
end