Created
July 27, 2012 22:17
-
-
Save hone/3190730 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
RUN_TIME = 100 | |
RESCUE_TIME = 10 | |
TERMFILE = "term.txt" | |
class Job | |
def self.perform(run_time, rescue_time) | |
sleep(run_time) | |
puts "Processed job!" | |
rescue SignalException => e | |
sleep rescue_time | |
File.open(TERMFILE, 'w') do |file| | |
file.puts "Caught Signal Exception: #{e.message}" | |
end | |
end | |
end | |
if $0 == __FILE__ | |
require 'fileutils' | |
FileUtils.rm(TERMFILE) if File.exists?(TERMFILE) | |
pid = Kernel.fork do | |
Job.perform(RUN_TIME, RESCUE_TIME) | |
end | |
sleep(2) | |
Process.kill("TERM", pid) | |
Process.waitpid(pid) | |
if File.exists?(TERMFILE) && File.read(TERMFILE).match(/Caught Signal Exception/) | |
puts 'SUCCESS!' | |
else | |
puts 'FAILURE' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment