Skip to content

Instantly share code, notes, and snippets.

@marktriggs
Created June 7, 2017 01:41
Show Gist options
  • Save marktriggs/eda15744c73baf18bf851df837ee0550 to your computer and use it in GitHub Desktop.
Save marktriggs/eda15744c73baf18bf851df837ee0550 to your computer and use it in GitHub Desktop.
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