Sure, here is the class.
class Client
include Typhoeus
def initialize
@logger = WebHook::Logger.new
end
def enqueue(job,servers,timeout=Config.client_timeout)
servers.each do |server|
begin
url = Config.server_to_uri(server)
resp =
self.class.post(url, :body => job.to_json, :headers
=> {'Content-Type' => 'application/json'}, :timeout => timeout )
if resp.code.to_i == 200
@logger.debug("client enqueue: timeout = #{timeout}, time
= #{resp.time}, url = #{url} code = #{resp.code} body = #{resp.body}")
return true
else
@
logger.info("client enqueue error: timeout = #{timeout},
time = #{resp.time}, url = #{url} code = #{resp.code} body = #
{resp.body}")
next
end
rescue Errno::ECONNREFUSED
@
logger.info("client enqueue error: connection refused #
{url}")
next
rescue Exception => e
@
logger.info("client enqueue error: #{url} #{e.to_s}")
return false
end
end
return false
end
end