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.
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 |
# File 'lib/openc3/top_level.rb', line 407 def self.safe_thread(name, retry_attempts = 0) Thread.new do retry_count = 0 begin yield rescue => error Logger.error "#{name} thread unexpectedly died. Retries: #{retry_count} of #{retry_attempts}" Logger.error error.formatted retry_count += 1 if retry_count <= retry_attempts self.write_exception_file(error) retry end handle_fatal_exception(error) end end end |