class PlabCheck

Public Class Methods

check(argument) click to toggle source
# File lib/plab-check.rb, line 5
def self.check(argument)
  if (argument.nil? || argument.eql?(""))
    puts "Usage: plab-check [your_url]"
    return
  end

  t = Thread.new do
    while true do
      begin
        uri = URI(argument)
        response = Net::HTTP.get_response(uri)
        json = JSON.parse(response.body)
        if (json["status"] == "FINISHED")
          system "terminal-notifier -title 'Placelab Checker' -message 'Your placelab job has finished 🎉'"
          puts "Finished? Hell yeah!"
          break;
        else
          puts "Finished? Nope"
        end
        sleep 5
      rescue Exception => ex
        puts "An error of type #{ex.class} happened, message is #{ex.message}"
        break
      end
    end
  end
  
  t.join()
end