YUKI Hiroshi
null+****@clear*****
Tue Mar 24 16:03:49 JST 2015
YUKI Hiroshi 2015-03-24 16:03:49 +0900 (Tue, 24 Mar 2015) New Revision: fd5517fa2fbe039be70e9b2f826a9a6bc6784329 https://github.com/droonga/droonga-engine/commit/fd5517fa2fbe039be70e9b2f826a9a6bc6784329 Message: Add ability to output details of Serf commands Modified files: lib/droonga/serf.rb lib/droonga/serf/command.rb Modified: lib/droonga/serf.rb (+3 -1) =================================================================== --- lib/droonga/serf.rb 2015-03-24 15:33:36 +0900 (f70c8b9) +++ lib/droonga/serf.rb 2015-03-24 16:03:49 +0900 (b22ef67) @@ -37,9 +37,10 @@ module Droonga include Loggable - def initialize(name) + def initialize(name, options={}) @serf = nil @name = name + @verbose = @options[:verbose] || false @service_installation = ServiceInstallation.new @node_metadata = NodeMetadata.new end @@ -183,6 +184,7 @@ module Droonga command = Command.new(@serf, command, "-rpc-addr", rpc_address, *options) + command.verbose = @verbose command.run end Modified: lib/droonga/serf/command.rb (+11 -0) =================================================================== --- lib/droonga/serf/command.rb 2015-03-24 15:33:36 +0900 (6234e26) +++ lib/droonga/serf/command.rb 2015-03-24 16:03:49 +0900 (139df7a) @@ -14,6 +14,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA require "open3" +require "pp" require "droonga/loggable" @@ -22,11 +23,13 @@ module Droonga class Command class Failure < Error attr_reader :command_line, :exit_status, :output, :error + attr_accessor :verbose def initialize(command_line, exit_status, output, error) @command_line = command_line @exit_status = exit_status @output = output @error = error + @verbose = false message = "Failed to run serf: (#{@exit_status}): " message << "#{@error.strip}[#{@output.strip}]: " message << @command_line.join(" ") @@ -44,12 +47,20 @@ module Droonga def run command_line = [@serf, @command] + @options + p command_line if @verbose stdout, stderror, status = Open3.capture3(*command_line, :pgroup => true) unless status.success? raise Failure.new(command_line, status.to_i, stdout, stderror) end logger.error("run: #{stderror}") unless stderror.empty? + if @verbose + begin + pp JSON.parse(stdout) + rescue JSON::ParserError + p stdout + end + end stdout end -------------- next part -------------- HTML����������������������������... Télécharger