require 'timeout'
def test
Timeout.timeout(5) do # 5 seconds
sleep 6
end
rescue
puts 'timeout'
end
begin
Timeout.timeout(5) do
# logic
sleep 10
puts "End of processing"
end
rescue Timeout::Error
puts "Took longer than 5 seconds!"
end