Module: DistribCore::Leader::DRbCallable

Defined in:
lib/distrib_core/leader/drb_callable.rb

Overview

A wrapper for methods available through DRb. Use this module to wrap DRb exposed methods to handle and log any error.

Instance Method Summary collapse

Instance Method Details

#drb_callable(method_name) ⇒ Object

Wraps the method. If it raises exception - logs it and calls ‘handle_non_example_exception`

Examples:

drb_callable def ping
  puts 'pong'
end

Parameters:

  • method_name (Symbol)

Returns:

  • NilClass



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/distrib_core/leader/drb_callable.rb', line 17

def drb_callable(method_name) # rubocop:disable Metrics/MethodLength:
  alias_method "drb_callable_#{method_name}", method_name

  define_method method_name do |*args| # rubocop:disable Metrics/MethodLength:
    if DistribCore::DRbHelper.drb_unknown?(*args)
      handle_non_example_exception
      nil
    else
      public_send("drb_callable_#{method_name}", *args)
    end
  rescue StandardError => e
    logger.error "Failed to call #{method_name}"
    logger.error e
    handle_non_example_exception
    nil
  end
end