Sha256: 289b77a5c6fab2a25e4053f893fd154d71a492c94027fe99381245e3f5796634

Contents?: true

Size: 1.16 KB

Versions: 10

Compression:

Stored size: 1.16 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 # rubocop:disable Metrics/AbcSize
          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

10 entries across 10 versions & 2 rubygems

Version Path
legion-transport-1.2.0 lib/legion/transport/messages/subtask.rb
legion-transport-1.1.9 lib/legion/transport/messages/subtask.rb
legion-transport-1.1.8 lib/legion/transport/messages/subtask.rb
legion-transport-1.1.6 lib/legion/transport/messages/subtask.rb
legion-transport-1.1.5 lib/legion/transport/messages/subtask.rb
legion-transport-java-1.1.3 lib/legion/transport/messages/subtask.rb
legion-transport-1.1.3 lib/legion/transport/messages/subtask.rb
legion-transport-1.1.2 lib/legion/transport/messages/subtask.rb
legion-transport-1.1.1 lib/legion/transport/messages/subtask.rb
legion-transport-1.1.0 lib/legion/transport/messages/subtask.rb