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