Created
September 29, 2017 09:53
-
-
Save dhiemstra/41a631a4f04aabefd4b20787bfb4fd85 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
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