-
-
Save mattetti/d1d031a960af3d3a9e20 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'eventmachine' | |
require 'em-http' | |
module SCEA | |
class Server | |
def self.start | |
new_size = EventMachine.set_descriptor_table_size(20000) | |
puts "New fd table size is: #{new_size}" | |
EventMachine.epoll # use epoll where available | |
EventMachine.run do | |
EventMachine.add_periodic_timer(5){ HttpFetcher.do_it } | |
end | |
end | |
end | |
class HttpFetcher | |
def self.do_it | |
begin | |
http = EventMachine::HttpRequest.new('https://gist.github.com/raw/8ea88329fdc71337c95a/5356f2dca3615022050d0c91930ddb333eb2819d/gistfile1.xsl').get( | |
:head => { | |
'User-Agent' => 'ruby-test', | |
'X-Test' => 'test' | |
} | |
) | |
http.callback do | |
if http.response_header.status != 200 | |
puts "request failed: #{http.response_header.http_status} #{http.response_header.http_reason}" | |
else | |
puts "request succeeded: #{http.response_header.http_status} #{http.response_header.http_reason}" | |
end | |
end | |
http.errback do | |
errors = http.errors && http.errors != '' ? http.errors : 'Unknown error (server down?)' | |
puts "request failed: #{errors}" | |
end | |
rescue => e | |
puts "Failure (exception): #{e.prettify}" | |
end | |
end | |
end | |
end | |
SCEA::Server.start |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment