Class: Droonga::Command::SerfEventHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/droonga/command/serf_event_handler.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSerfEventHandler

Returns a new instance of SerfEventHandler.



30
31
32
# File 'lib/droonga/command/serf_event_handler.rb', line 30

def initialize
  @payload = nil
end

Class Method Details

.runObject



25
26
27
# File 'lib/droonga/command/serf_event_handler.rb', line 25

def run
  new.run
end

Instance Method Details

#runObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/droonga/command/serf_event_handler.rb', line 34

def run
  command_class = detect_command_class
  return true if command_class.nil?

  serf_name = ENV["SERF_SELF_NAME"]
  command = command_class.new(serf_name, @payload)
  begin
    command.process if command.should_process?
  rescue Exception => exception
    command.log("Exception: #{exception.inspect}, #{exception.message}, #{exception.backtrace.join(", ")}")
    raise exception
  ensure
    output_response(command.response)
  end
  true
rescue Exception => exception
  #XXX Any exception blocks following serf operations.
  #    To keep it working, I rescue any exception for now.
  begin
    FileUtils.mkdir_p(Path.serf_event_handler_errors)
    File.open(Path.serf_event_handler_error_file, "w") do |file|
      file.write(exception.inspect)
      file.write(exception.backtrace)
    end
  rescue Errno::EACCES => permission_denied_exception
  end
  puts exception.inspect
  puts exception.backtrace
  true
end