Created
June 7, 2017 01:41
-
-
Save marktriggs/eda15744c73baf18bf851df837ee0550 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 'atomic' | |
class Watchdog | |
def initialize(description) | |
@description = description | |
@finished = Atomic.new(false) | |
@thread = Thread.new do | |
run_monitor | |
end | |
end | |
def finished! | |
@finished.update {|_| true} | |
end | |
def run_monitor | |
loop do | |
sleep 5 | |
if @finished.value | |
break | |
else | |
$stderr.puts "#{Time.now} Request still running: #{@description}" | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment