Class: GroongaDelta::LocalDelta::CommandProcessor

Inherits:
Groonga::Client::CommandProcessor
  • Object
show all
Defined in:
lib/groonga-delta/local-delta.rb

Instance Method Summary collapse

Constructor Details

#initialize(config, *args) ⇒ CommandProcessor

Returns a new instance of CommandProcessor.



72
73
74
75
# File 'lib/groonga-delta/local-delta.rb', line 72

def initialize(config, *args)
  @config = config
  super(*args)
end

Instance Method Details

#process_response(response, command) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/groonga-delta/local-delta.rb', line 77

def process_response(response, command)
  message = ""
  case command.command_name
  when "load"
    command.arguments.delete(:values)
    if response.success?
      message = "#{response.n_loaded_records}: "
    else
      load_response = Groonga::Client::Response::Load.new(command,
                                                          response.header,
                                                          response.body)
      message = "#{load_response.n_loaded_records}: "
    end
  end
  if response.success?
    @config.logger.info("Processed: " +
                        "#{response.elapsed_time}: " +
                        "#{command.command_name}: " +
                        message +
                        "#{command.to_command_format}")
  else
    failed_message = "Failed to process: " +
                     "#{response.return_code}: " +
                     "#{response.elapsed_time}: " +
                     "#{response.error_message}: " +
                     "#{command.command_name}: " +
                     message +
                     "#{command.to_command_format}"
    case @config.on_error
    when "ignore"
    when "warning"
      @config.logger.warn(failed_message)
    when "error"
      raise ExecutionError, failed_message
    end
  end
end