[Groonga-commit] droonga/droonga-engine at 968e994 [master] Run and finish asynchronous commands correctly

アーカイブの一覧に戻る

YUKI Hiroshi null+****@clear*****
Tue Apr 14 14:20:08 JST 2015


YUKI Hiroshi	2015-04-14 14:20:08 +0900 (Tue, 14 Apr 2015)

  New Revision: 968e994fb248f4deac298ee94f1f8fe39770beea
  https://github.com/droonga/droonga-engine/commit/968e994fb248f4deac298ee94f1f8fe39770beea

  Message:
    Run and finish asynchronous commands correctly

  Modified files:
    lib/droonga/plugin/async_command.rb
    lib/droonga/plugins/dump.rb
    lib/droonga/plugins/system/absorb_data.rb

  Modified: lib/droonga/plugin/async_command.rb (+1 -1)
===================================================================
--- lib/droonga/plugin/async_command.rb    2015-04-14 12:58:18 +0900 (322a56a)
+++ lib/droonga/plugin/async_command.rb    2015-04-14 14:20:08 +0900 (4f6ff66)
@@ -98,7 +98,6 @@ module Droonga
 
           runner = Fiber.new do
             handle
-            forward("#{prefix}.end")
           end
 
           timer = Coolio::TimerWatcher.new(0.1, true)
@@ -130,6 +129,7 @@ module Droonga
 
         def handle
           #XXX override me!!
+          forward("#{prefix}.end") #XXX you must forward "end" message by self!
         end
 
         def setup_forward_data

  Modified: lib/droonga/plugins/dump.rb (+1 -0)
===================================================================
--- lib/droonga/plugins/dump.rb    2015-04-14 12:58:18 +0900 (fdfa768)
+++ lib/droonga/plugins/dump.rb    2015-04-14 14:20:08 +0900 (cd4338e)
@@ -67,6 +67,7 @@ module Droonga
           dump_schema
           dump_records
           dump_indexes
+          forward("#{prefix}.end")
         end
 
         def dump_schema

  Modified: lib/droonga/plugins/system/absorb_data.rb (+26 -6)
===================================================================
--- lib/droonga/plugins/system/absorb_data.rb    2015-04-14 12:58:18 +0900 (fd6740d)
+++ lib/droonga/plugins/system/absorb_data.rb    2015-04-14 14:20:08 +0900 (7db8cbf)
@@ -56,7 +56,12 @@ module Droonga
           end
 
           def handle
+            @dumper_error_message = nil
+
             dumper = Drndump::Dumper.new(dumper_params)
+            dumper.on_finish = lambda do
+              on_finish
+            end
 
             @start_time = Time.now
 
@@ -66,7 +71,8 @@ module Droonga
               get_total_n_source_records do |count|
                 @total_n_source_records = count
               end
-              dumper_error_message = dumper.run do |message|
+              @dumper_error_message = dumper.run do |message|
+                begin
                 message["dataset"] = current_dataset
                 @messenger.forward(message,
                                    "to"   => my_node_name,
@@ -76,16 +82,30 @@ module Droonga
                 if (elapsed_seconds % progress_interval_seconds).zero?
                   report_progress
                 end
+                rescue Exception => exception
+                  @dumper_error_message
+                  on_finish
+                end
               end
-              @total_n_source_records = @n_processed_messages
-              report_progress
             rescue Exception => exception
-              dumper_error_message = exception.to_s
+              @dumper_error_message = exception.to_s
+              on_finish
             end
+          end
 
-            if dumper_error_message
-              error(error_name, dumper_error_message)
+          def on_finish
+            begin
+              if @dumper_error_message
+                error(error_name, @dumper_error_message)
+              else
+                @total_n_source_records = @n_processed_messages
+                report_progress
+              end
+            rescue Exception => exception
+              @dumper_error_message = exception.to_s
+              error(error_name, @dumper_error_message)
             end
+            forward("#{prefix}.end")
           end
 
           def dumper_params
-------------- next part --------------
HTML����������������������������...
ダウンロード 



More information about the Groonga-commit mailing list
アーカイブの一覧に戻る