Skip to content

Instantly share code, notes, and snippets.

@dhiemstra
Created September 29, 2017 09:53
Show Gist options
  • Save dhiemstra/41a631a4f04aabefd4b20787bfb4fd85 to your computer and use it in GitHub Desktop.
Save dhiemstra/41a631a4f04aabefd4b20787bfb4fd85 to your computer and use it in GitHub Desktop.
class HealthCheck
class << self
def run(port: 8000)
self.new(port: port).run
end
def background(port: 8000)
self.new(port: port).background
end
end
attr_reader :server, :port, :thread
def initialize(port: 8000)
@port = port
@server = TCPServer.new(port)
end
def run
loop do
client = server.accept
client.puts "OK"
client.close
end
end
def background
Thread.abort_on_exception = true
Thread.kill(thread) if thread && thread.alive?
@thread = Thread.new { run }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment