[Groonga-commit] droonga/drndump at 0bb2fa1 [master] Add ability to handle errors

Back to archive index

YUKI Hiroshi null+****@clear*****
Wed Apr 15 18:13:20 JST 2015


YUKI Hiroshi	2015-04-15 18:13:20 +0900 (Wed, 15 Apr 2015)

  New Revision: 0bb2fa138b2f1b374598ce89442cc5226d0aa43c
  https://github.com/droonga/drndump/commit/0bb2fa138b2f1b374598ce89442cc5226d0aa43c

  Message:
    Add ability to handle errors

  Modified files:
    lib/drndump/dump_client.rb

  Modified: lib/drndump/dump_client.rb (+21 -3)
===================================================================
--- lib/drndump/dump_client.rb    2015-04-15 17:36:22 +0900 (b4b7a07)
+++ lib/drndump/dump_client.rb    2015-04-15 18:13:20 +0900 (4afcf75)
@@ -20,7 +20,7 @@ require "droonga/client"
 module Drndump
   class DumpClient
     attr_reader :error_message
-    attr_writer :on_finish, :on_progress
+    attr_writer :on_finish, :on_progress, :on_error
 
     def initialize(params)
       @host     = params[:host]
@@ -35,11 +35,15 @@ module Drndump
 
       @on_finish = nil
       @on_progress = nil
+      @on_error = nil
     end
 
     def run(options={}, &block)
       extra_client_options = options[:client_options] || {}
       client = Droonga::Client.new(client_options.merge(extra_client_options))
+      client.on_error = lambda do |error|
+        on_error(error)
+      end
 
       n_dumpers = 0
 
@@ -53,9 +57,10 @@ module Drndump
         "body"    => dump_params,
       }
       client.subscribe(dump_message) do |message|
-        @on_progress.call(message) if @on_progress
+        on_progress(message)
         case message
         when Droonga::Client::Error
+          on_error(message)
           client.close
           @error_message = message.to_s
         else
@@ -64,6 +69,7 @@ module Drndump
             if message["statusCode"] != 200
               client.close
               error = message["body"]
+              on_error(message)
               @error_message = "#{error['name']}: #{error['message']}"
             end
           when "dump.table"
@@ -83,7 +89,7 @@ module Drndump
             n_dumpers -= 1
             if n_dumpers <= 0
               client.close
-              @on_finish.call if @on_finish
+              on_finish
             end
           end
         end
@@ -177,5 +183,17 @@ module Drndump
 
       column_create_message
     end
+
+    def on_finish
+      @on_finish.call if @on_finish
+    end
+
+    def on_progress(message)
+      @on_progress.call(message) if @on_progress
+    end
+
+    def on_error(error)
+      @on_error.call(error) if @on_error
+    end
   end
 end
-------------- next part --------------
HTML����������������������������...
Download 



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