[Groonga-commit] ranguba/groonga-client at 68f85de [master] Support changing timeout on reading response from Groonga server

Back to archive index

Kouhei Sutou null+****@clear*****
Tue May 12 14:36:31 JST 2015


Kouhei Sutou	2015-05-12 14:36:31 +0900 (Tue, 12 May 2015)

  New Revision: 68f85de6314e1c2d70e31ae74cf64af07c7c0430
  https://github.com/ranguba/groonga-client/commit/68f85de6314e1c2d70e31ae74cf64af07c7c0430

  Message:
    Support changing timeout on reading response from Groonga server

  Added files:
    lib/groonga/client/default.rb
  Modified files:
    lib/groonga/client.rb
    lib/groonga/client/command-line/groonga-client.rb
    lib/groonga/client/protocol/http/synchronous.rb

  Modified: lib/groonga/client.rb (+3 -1)
===================================================================
--- lib/groonga/client.rb    2015-04-21 09:57:17 +0900 (40bfbfc)
+++ lib/groonga/client.rb    2015-05-12 14:36:31 +0900 (424c702)
@@ -1,7 +1,7 @@
 # -*- coding: utf-8 -*-
 #
 # Copyright (C) 2013  Haruka Yoshihara <yoshihara �� clear-code.com>
-# Copyright (C) 2013-2014  Kouhei Sutou <kou �� clear-code.com>
+# Copyright (C) 2013-2015  Kouhei Sutou <kou �� clear-code.com>
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -17,6 +17,7 @@
 # License along with this library; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
+require "groonga/client/default"
 require "groonga/client/command"
 require "groonga/client/empty-request"
 require "groonga/client/protocol/gqtp"
@@ -64,6 +65,7 @@ module Groonga
     def initialize(options={})
       options = options.dup
       protocol = options.delete(:protocol) || :gqtp
+      options[:read_timeout] ||= Default::READ_TIMEOUT
 
       @connection = nil
       if protocol == :gqtp

  Modified: lib/groonga/client/command-line/groonga-client.rb (+10 -0)
===================================================================
--- lib/groonga/client/command-line/groonga-client.rb    2015-04-21 09:57:17 +0900 (08a11f2)
+++ lib/groonga/client/command-line/groonga-client.rb    2015-05-12 14:36:31 +0900 (99b7647)
@@ -31,6 +31,8 @@ module Groonga
           @host     = "localhost"
           @port     = nil
 
+          @read_timeout = Default::READ_TIMEOUT
+
           @runner_options = {
             :split_load_chunk_size => 10000,
           }
@@ -42,6 +44,7 @@ module Groonga
           @client = Groonga::Client.new(:protocol => @protocol,
                                         :host     => @host,
                                         :port     => @port,
+                                        :read_timeout => @read_timeout,
                                         :backend  => :synchronous)
           runner = Runner.new(@client, @runner_options)
 
@@ -92,6 +95,13 @@ module Groonga
             @port = port
           end
 
+          parser.on("--read-timeout=TIMEOUT", Integer,
+                    "Timeout on reading response from Groonga server.",
+                    "You can disable timeout by specifying -1.",
+                    "(#{@read_timeout})") do |timeout|
+            @read_timeout = timeout
+          end
+
           parser.on("--split-load-chunk-size=SIZE", Integer,
                     "Split a large load to small loads.",
                     "Each small load has at most SIZE records.",

  Added: lib/groonga/client/default.rb (+25 -0) 100644
===================================================================
--- /dev/null
+++ lib/groonga/client/default.rb    2015-05-12 14:36:31 +0900 (f2f6fc3)
@@ -0,0 +1,25 @@
+# Copyright (C) 2015  Kouhei Sutou <kou �� clear-code.com>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+
+module Groonga
+  class Client
+    module Default
+      # The default timeout on reading response from Groonga server in
+      # seconds.
+      READ_TIMEOUT = 60
+    end
+  end
+end

  Modified: lib/groonga/client/protocol/http/synchronous.rb (+10 -0)
===================================================================
--- lib/groonga/client/protocol/http/synchronous.rb    2015-04-21 09:57:17 +0900 (a3a19db)
+++ lib/groonga/client/protocol/http/synchronous.rb    2015-05-12 14:36:31 +0900 (33fc596)
@@ -35,6 +35,7 @@ module Groonga
           def send(command)
             begin
               Net::HTTP.start(@host, @port) do |http|
+                http.read_timeout = read_timeout
                 response = send_request(http, command)
                 case response
                 when Net::HTTPSuccess, Net::HTTPBadRequest
@@ -89,6 +90,15 @@ module Groonga
           end
 
           private
+          def read_timeout
+            timeout = @options[:read_timeout]
+            if timeout < 0
+              nil
+            else
+              timeout
+            end
+          end
+
           def send_request(http, command)
             if command.name == "load"
               raw_values = command[:values]
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index