Skip to content

Instantly share code, notes, and snippets.

@blasterpal
Created February 18, 2011 15:25
Show Gist options
  • Select an option

  • Save blasterpal/833810 to your computer and use it in GitHub Desktop.

Select an option

Save blasterpal/833810 to your computer and use it in GitHub Desktop.
Nested System Timer Test
require 'rubygems'
require 'system_timer'
class JobWrapper
attr_accessor :timeout, :job, :name
# slowjob1 = SlowJob.new(15,'slowjob1')
# wrapper = JobWrapper.new(10,slowjob1)
# wrapper2 = JobWrapper.new(5,wrapper)
def initialize(timeout,job)
@timeout = timeout
@job = job
@name = job.to_s
end
def run()
begin
SystemTimer.timeout(timeout) do
#do_something_that_could_take_a_long_time
job.run
end
rescue Timeout::Error
puts "job #{job.name} has timed-out"
end
end
end
class SlowJob
attr_accessor :length,:name
def initialize(length,name)
@length = length
@name = name
end
def run
length.times do
putc '.'
sleep 1
end
puts ''
puts 'done with slow job'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment