Class: Daemon::Runner::ErrorsHandling

Inherits:
Object
  • Object
show all
Defined in:
lib/onapp/engine/runner/errors_handling.rb

Instance Method Summary (collapse)

Constructor Details

- (ErrorsHandling) initialize(app)

Returns a new instance of ErrorsHandling



6
7
8
# File 'lib/onapp/engine/runner/errors_handling.rb', line 6

def initialize(app)
  @app = app
end

Instance Method Details

- (Object) call(env)



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/onapp/engine/runner/errors_handling.rb', line 10

def call(env)
  require 'availability/fault_tolerance'

  abort_on_exception, Thread.abort_on_exception = Thread.abort_on_exception, true

  reactor_error = nil

  error_reaction = Proc.new do |exception|
    Daemon.log_deactivation(exception, "Pausing Daemon due to errors:")
  end

  EM.error_handler do |e|
    Daemon.logger.error("Daemon encountered an issue: #{e.class}: #{e.message}")
    Daemon.logger.debug(e.backtrace.join("\n"))
    reactor_error = e
  end

  Daemon::Utils::Retry.retry(Redis::BaseError, SystemCallError, on_error: error_reaction) do
    @app.call(env)
    raise reactor_error if reactor_error
  end
rescue Exception => ex
  unless ex.is_a?(SystemExit)
    Daemon.alert_daemon_down(ex) rescue nil
    $stderr.puts ex
    $stderr.puts ex.backtrace
  end
  raise ex
ensure
  Thread.abort_on_exception = abort_on_exception
end