Sha256: 39880ab34202dc3e6c1c75a37c206e32d64dcec53816ad0df973ab1f18b1294a

Contents?: true

Size: 1.16 KB

Versions: 14

Compression:

Stored size: 1.16 KB

Contents

require "concurrent"
require "rest-client"

module Sqspoller
  class WorkerTask

    ALLOWED_METHODS = { 'post' => :post,
                        'get'  => :get
                      }

    def initialize worker_configuration
      @http_method = ALLOWED_METHODS[worker_configuration[:http_method].downcase]
      @http_url = worker_configuration[:http_url]
      @timeout = worker_configuration[:timeout] && worker_configuration[:timeout].to_i || 450
    end

    def process(message, _message_id)
      if @http_method
        RestClient::Request.execute(:method => @http_method,
                                    :url => @http_url,
                                    :payload => message,
                                    :headers => HEADERS,
                                    :timeout => @timeout,
                                    :open_timeout => 5) do |response, request, result|
          case response.code
          when 200
            return "OK"
          else
            raise "Service did not return 200 OK response. #{response.code}"
          end
        end
      else
        raise "Invalid http_method provided. #{http_method}"
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
fk-redis-sqspoller-0.1.2.5.8 lib/sqspoller/worker_task.rb
fk-redis-sqspoller-0.1.2.5.7 lib/sqspoller/worker_task.rb
fk-redis-sqspoller-0.1.2.5.6 lib/sqspoller/worker_task.rb
fk-redis-sqspoller-0.1.2.5.6.alpha lib/sqspoller/worker_task.rb
fk-redis-sqspoller-0.1.2.5.5.alpha lib/sqspoller/worker_task.rb
fk-redis-sqspoller-0.1.2.5.4.alpha lib/sqspoller/worker_task.rb
fk-redis-sqspoller-0.1.2.5.3.alpha lib/sqspoller/worker_task.rb
fk-redis-sqspoller-0.1.2.5.2.alpha lib/sqspoller/worker_task.rb
fk-redis-sqspoller-0.1.2.5.1.alpha lib/sqspoller/worker_task.rb
fk-redis-sqspoller-0.1.2.5.alpha lib/sqspoller/worker_task.rb
fk-redis-sqspoller-0.1.2.4.alpha lib/sqspoller/worker_task.rb
fk-redis-sqspoller-0.1.2.2 lib/sqspoller/worker_task.rb
fk-redis-sqspoller-0.1.2.1 lib/sqspoller/worker_task.rb
fk-redis-sqspoller-0.1.2 lib/sqspoller/worker_task.rb