YUKI Hiroshi
null+****@clear*****
Mon Apr 6 20:18:53 JST 2015
YUKI Hiroshi 2015-04-06 20:18:53 +0900 (Mon, 06 Apr 2015) New Revision: 43bf6f2110bb25382a595a1efa5f6f7bd3c91124 https://github.com/droonga/droonga-engine/commit/43bf6f2110bb25382a595a1efa5f6f7bd3c91124 Message: Use "timeout" parameter given as a part of request messages Modified files: lib/droonga/dispatcher.rb lib/droonga/engine_state.rb lib/droonga/single_step_definition.rb Modified: lib/droonga/dispatcher.rb (+23 -1) =================================================================== --- lib/droonga/dispatcher.rb 2015-04-06 20:05:00 +0900 (f8ac086) +++ lib/droonga/dispatcher.rb 2015-04-06 20:18:53 +0900 (7dac181) @@ -172,7 +172,9 @@ module Droonga dataset = message["dataset"] || @message["dataset"] collector_runner = @collector_runners[dataset] session = session_planner.create_session(id, self, collector_runner) - @engine_state.register_session(id, session) + timeout_seconds = message["timeout_seconds"] || nil + @engine_state.register_session(id, session, + :timeout_seconds => timeout_seconds) else logger.error("no steps error", :id => id, :message => message) return @@ -208,7 +210,13 @@ module Droonga id = @engine_state.generate_id destinations = [] + timeout_seconds = nil steps.each do |step| + calculated_timeout_seconds = timeout_seconds_from_step(step) + if calculated_timeout_seconds + timeout_seconds = calculated_timeout_seconds + end + dataset =****@catal*****(step["dataset"]) if dataset if write_step?(step) @@ -236,6 +244,7 @@ module Droonga else step["routes"] ||= [id] end + destinations += step["routes"].collect do |route| internal_farm_path(route) end @@ -244,6 +253,7 @@ module Droonga dispatch_message = { "id" => id, "steps" => steps, + "timeout_seconds" => timeout_seconds, } destinations.uniq.each do |destination| dispatch(dispatch_message, destination) @@ -293,6 +303,18 @@ module Droonga step_definition.write? end + def timeout_seconds_from_step(step) + return nil unless step["dataset"] + + step_runner = @step_runners[step["dataset"]] + return nil unless step_runner + + step_definition = step_runner.find(step["command"]) + return nil unless step_definition + + step_definition.timeout_seconds_for_step(step) + end + private def internal_route(route) @engine_state.internal_route(route) Modified: lib/droonga/engine_state.rb (+4 -2) =================================================================== --- lib/droonga/engine_state.rb 2015-04-06 20:05:00 +0900 (76191ba) +++ lib/droonga/engine_state.rb 2015-04-06 20:18:53 +0900 (2221d88) @@ -124,10 +124,12 @@ module Droonga @sessions[id] end - def register_session(id, session) + def register_session(id, session, options={}) @sessions[id] = session logger.trace("new session #{id} is registered. rest sessions=#{@sessions.size}") - session.set_timeout(@loop, DEFAULT_SESSION_TIMEOUT_SECONDS) do + + timeout_seconds = options[:timeout_seconds] || DEFAULT_SESSION_TIMEOUT_SECONDS + session.set_timeout(@loop, timeout_seconds) do logger.trace("session #{id} is timed out!") unregister_session(id) end Modified: lib/droonga/single_step_definition.rb (+18 -0) =================================================================== --- lib/droonga/single_step_definition.rb 2015-04-06 20:05:00 +0900 (b005343) +++ lib/droonga/single_step_definition.rb 2015-04-06 20:18:53 +0900 (69dd274) @@ -19,6 +19,7 @@ module Droonga attr_accessor :handler attr_accessor :collector attr_writer :write + attr_writer :timeout_seconds_calculator attr_accessor :inputs attr_accessor :output def initialize(plugin_module) @@ -27,6 +28,15 @@ module Droonga @handler = nil @collector = nil @write = false + @timeout_seconds_calculator = lambda do |step| + if step["timeout"] + return step["timeout"] + elsif step["body"] + return step["body"]["timeout"] if step["body"]["timeout"] + end + nil + end + @inputs = [] @output = {} yield(self) @@ -36,6 +46,14 @@ module Droonga @write end + def timeout_seconds_for_step(step) + if @timeout_seconds_calculator + @timeout_seconds_calculator.call(step) + else + nil + end + end + def handler_class resolve_class(@handler) end -------------- next part -------------- HTML����������������������������...Download