Method: OpenC3.safe_thread
- Defined in:
- lib/openc3/top_level.rb
.safe_thread(name, retry_attempts = 0) ⇒ Object
Creates a Ruby Thread to run the given block. Rescues any exceptions and retries the threads the given number of times before handling the thread death by calling handle_fatal_exception.
413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 |
# File 'lib/openc3/top_level.rb', line 413 def self.safe_thread(name, retry_attempts = 0) Thread.new do retry_count = 0 begin yield rescue => e Logger.error "#{name} thread unexpectedly died. Retries: #{retry_count} of #{retry_attempts}" Logger.error e.formatted retry_count += 1 if retry_count <= retry_attempts self.write_exception_file(e) retry end handle_fatal_exception(e) end end end |