YUKI Hiroshi
null+****@clear*****
Mon Apr 20 14:49:13 JST 2015
YUKI Hiroshi 2015-04-20 14:49:13 +0900 (Mon, 20 Apr 2015) New Revision: 8aac6da5c495198c371dfce50c9b1de1dcd32978 https://github.com/droonga/droonga-client-ruby/commit/8aac6da5c495198c371dfce50c9b1de1dcd32978 Message: Add ability to specify default timeout seconds Modified files: lib/droonga/client.rb lib/droonga/client/message_completer.rb lib/droonga/command/base.rb Modified: lib/droonga/client.rb (+2 -1) =================================================================== --- lib/droonga/client.rb 2015-04-20 14:44:44 +0900 (f9c0bc3) +++ lib/droonga/client.rb 2015-04-20 14:49:13 +0900 (ed24a54) @@ -30,6 +30,7 @@ module Droonga DEFAULT_PORT = 10031 DEFAULT_TAG = "droonga" DEFAULT_DATASET = "Default" + DEFAULT_TIMEOUT_SECONDS = 3 attr_writer :on_error @@ -89,7 +90,7 @@ module Droonga @completion = options[:completion] != false @validation = options[:validation] != false - @completer = MessageCompleter.new + @completer = MessageCompleter.new(:default_timeout => options[:default_timeout]) @validator = MessageValidator.new end Modified: lib/droonga/client/message_completer.rb (+10 -0) =================================================================== --- lib/droonga/client/message_completer.rb 2015-04-20 14:44:44 +0900 (9cf3eb2) +++ lib/droonga/client/message_completer.rb 2015-04-20 14:49:13 +0900 (6975717) @@ -23,11 +23,15 @@ module Droonga def initialize(options={}) @options = options @fixed_date = @options[:fixed_date] + @default_timeout = @options[:default_timeout] end def complete(message) id = message["id"] || generate_id date = message["date"] || @fixed_date || new_date + if not have_timeout?(message) and @default_timeout + message["timeout"] = @default_timeout + end message.merge("id" => id, "date" => date) end @@ -41,6 +45,12 @@ module Droonga def new_date Time.now.utc.iso8601(MICRO_SECONDS_DECIMAL_PLACE) end + + def have_timeout?(message) + return true if message["timeout"] + return false unless message["body"].is_a?(Hash) + not message["body"]["timeout"].nil? + end end end end Modified: lib/droonga/command/base.rb (+4 -0) =================================================================== --- lib/droonga/command/base.rb 2015-04-20 14:44:44 +0900 (39e71d9) +++ lib/droonga/command/base.rb 2015-04-20 14:49:13 +0900 (fb109c8) @@ -50,6 +50,9 @@ module Droonga option.on("receiver-host=", "Host name of this host.", :default => Client::DEFAULT_HOST) + option.on("timeout=", + "Time to terminate unresponsive connections (in seconds).", + :default => Client::DEFAULT_TIMEOUT_SECONDS) end @options = options rescue Slop::MissingOptionError => error @@ -65,6 +68,7 @@ module Droonga :protocol => :droonga, :receiver_host => @options["receiver-host"], :receiver_port => 0, + :default_timeout => @options[:timeout], } @client ||= Droonga::Client.new(options) end -------------- next part -------------- HTML����������������������������...Download