Navigation Menu

Skip to content

Commit

Permalink
Uniform timeout_seconds to timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Apr 20, 2015
1 parent 78ac94c commit 2b6334b
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 21 deletions.
18 changes: 9 additions & 9 deletions lib/droonga/dispatcher.rb
Expand Up @@ -173,9 +173,9 @@ def process_internal_message(message)
collector_runner = @collector_runners[dataset]
session = session_planner.create_session(id, self, collector_runner)
if session.need_result?
timeout_seconds = message["timeout_seconds"] || nil
timeout = message["timeout"] || nil
@engine_state.register_session(id, session,
:timeout_seconds => timeout_seconds)
:timeout => timeout)
session.start
logger.trace("process_internal_message: waiting for results")
else
Expand Down Expand Up @@ -218,11 +218,11 @@ def dispatch_steps(steps)
id = @engine_state.generate_id

destinations = []
timeout_seconds = nil
timeout = nil
steps.each do |step|
calculated_timeout_seconds = timeout_seconds_from_step(step)
if calculated_timeout_seconds
timeout_seconds = calculated_timeout_seconds
calculated_timeout = timeout_from_step(step)
if calculated_timeout
timeout = calculated_timeout
end

dataset = @catalog.dataset(step["dataset"])
Expand Down Expand Up @@ -261,7 +261,7 @@ def dispatch_steps(steps)
dispatch_message = {
"id" => id,
"steps" => steps,
"timeout_seconds" => timeout_seconds,
"timeout" => timeout,
}
destinations.uniq.each do |destination|
dispatch(dispatch_message, destination)
Expand Down Expand Up @@ -311,7 +311,7 @@ def write_step?(step)
step_definition.write?
end

def timeout_seconds_from_step(step)
def timeout_from_step(step)
return nil unless step["dataset"]

step_runner = @step_runners[step["dataset"]]
Expand All @@ -320,7 +320,7 @@ def timeout_seconds_from_step(step)
step_definition = step_runner.find(step["command"])
return nil unless step_definition

step_definition.timeout_seconds_for_step(step)
step_definition.timeout_for_step(step)
end

private
Expand Down
4 changes: 2 additions & 2 deletions lib/droonga/engine_state.rb
Expand Up @@ -128,8 +128,8 @@ def register_session(id, session, options={})
@sessions[id] = session
logger.trace("new session #{id} is registered. rest sessions=#{@sessions.size}")

timeout_seconds = options[:timeout_seconds] || DEFAULT_SESSION_TIMEOUT_SECONDS
session.set_timeout(@loop, timeout_seconds) do
timeout = options[:timeout] || DEFAULT_SESSION_TIMEOUT_SECONDS
session.set_timeout(@loop, timeout) do
logger.trace("session #{id} is timed out!")
unregister_session(id)
end
Expand Down
6 changes: 3 additions & 3 deletions lib/droonga/forwarder.rb
Expand Up @@ -35,8 +35,8 @@ def initialize(loop, options={})
@senders = {}
@auto_close_timers = {}
@shutting_down = false
@auto_close_timeout_seconds = options[:auto_close_timeout_seconds] ||
DEFAULT_AUTO_CLOSE_TIMEOUT_SECONDS
@auto_close_timeout = options[:auto_close_timeout] ||
DEFAULT_AUTO_CLOSE_TIMEOUT_SECONDS
end

def start
Expand Down Expand Up @@ -138,7 +138,7 @@ def set_auto_close_timer(host, port, params)
previous_timer = @auto_close_timers[destination]
previous_timer.detach if previous_timer

timer = Coolio::TimerWatcher.new(@auto_close_timeout_seconds)
timer = Coolio::TimerWatcher.new(@auto_close_timeout)
on_timeout = lambda do
timer.detach
@auto_close_timers.delete(destination)
Expand Down
4 changes: 2 additions & 2 deletions lib/droonga/session.rb
Expand Up @@ -115,8 +115,8 @@ def receive(name, value)
end
end

def set_timeout(loop, timeout_seconds, &on_timeout)
@timeout_timer = Coolio::TimerWatcher.new(timeout_seconds)
def set_timeout(loop, timeout, &on_timeout)
@timeout_timer = Coolio::TimerWatcher.new(timeout)
on_timer = lambda do
@timeout_timer.detach
@timeout_timer = nil
Expand Down
10 changes: 5 additions & 5 deletions lib/droonga/single_step_definition.rb
Expand Up @@ -19,7 +19,7 @@ class SingleStepDefinition
attr_accessor :handler
attr_accessor :collector
attr_writer :write, :single_operation
attr_writer :timeout_seconds_calculator
attr_writer :timeout_calculator
attr_accessor :inputs
attr_accessor :output
def initialize(plugin_module)
Expand All @@ -29,7 +29,7 @@ def initialize(plugin_module)
@collector = nil
@write = false
@single_operation = false
@timeout_seconds_calculator = lambda do |step|
@timeout_calculator = lambda do |step|
if step["timeout"]
return step["timeout"]
elsif step["body"]
Expand All @@ -52,9 +52,9 @@ def single_operation?
@single_operation
end

def timeout_seconds_for_step(step)
if @timeout_seconds_calculator
@timeout_seconds_calculator.call(step)
def timeout_for_step(step)
if @timeout_calculator
@timeout_calculator.call(step)
else
nil
end
Expand Down

0 comments on commit 2b6334b

Please sign in to comment.