Auto-terminate potentially long-running operations in Ruby