Sha256: 35982162bb50558b9f87f86ed767a9b200703276a0dc9f47b37ed4dc086f8847

Contents?: true

Size: 1.13 KB

Versions: 1

Compression:

Stored size: 1.13 KB

Contents

require 'legion/transport/exchanges/task'

module Legion
  module Transport
    module Messages
      class SubTask < Legion::Transport::Message
        def exchange
          Legion::Transport::Exchanges::Task
        end

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

        def routing_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
        end

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

          @valid = true
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
legion-transport-1.0.0 lib/legion/transport/messages/subtask.rb