Class: Pwrake::Runner
- Inherits:
-
Object
- Object
- Pwrake::Runner
- Defined in:
- lib/pwrake/iomux/runner.rb
Instance Attribute Summary collapse
-
#handler ⇒ Object
readonly
Returns the value of attribute handler.
Instance Method Summary collapse
- #add_handler(hdl) ⇒ Object
- #delete_handler(hdl) ⇒ Object
- #finish ⇒ Object
-
#get_host(io) ⇒ Object
used to print an error message.
-
#heartbeat(io) ⇒ Object
called when IO start and receive heartbeat.
-
#initialize(timeout = nil) ⇒ Runner
constructor
A new instance of Runner.
- #run ⇒ Object
Constructor Details
#initialize(timeout = nil) ⇒ Runner
Returns a new instance of Runner.
7 8 9 10 11 |
# File 'lib/pwrake/iomux/runner.rb', line 7 def initialize(timeout=nil) @timeout = timeout @handler = {} @hb_time = {} end |
Instance Attribute Details
#handler ⇒ Object (readonly)
Returns the value of attribute handler.
13 14 15 |
# File 'lib/pwrake/iomux/runner.rb', line 13 def handler @handler end |
Instance Method Details
#add_handler(hdl) ⇒ Object
15 16 17 |
# File 'lib/pwrake/iomux/runner.rb', line 15 def add_handler(hdl) @handler[hdl.ior] ||= hdl end |
#delete_handler(hdl) ⇒ Object
19 20 21 |
# File 'lib/pwrake/iomux/runner.rb', line 19 def delete_handler(hdl) @handler.delete(hdl.ior) end |
#finish ⇒ Object
42 43 44 45 46 |
# File 'lib/pwrake/iomux/runner.rb', line 42 def finish @handler.each do |io,hdl| hdl.finish end end |
#get_host(io) ⇒ Object
used to print an error message
49 50 51 52 |
# File 'lib/pwrake/iomux/runner.rb', line 49 def get_host(io) hdl = @handler[io] h = hdl.respond_to?(:host) ? hdl.host : nil end |
#heartbeat(io) ⇒ Object
called when IO start and receive heartbeat
55 56 57 58 59 |
# File 'lib/pwrake/iomux/runner.rb', line 55 def heartbeat(io) @hb_time[io] = Time.now @hb_earliest = @hb_time.values.min #Log.debug "heartbeat: host=#{get_host(io)}" end |
#run ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/pwrake/iomux/runner.rb', line 23 def run while !(io_set = @handler.keys).empty? sel, = IO.select(io_set,nil,nil,@timeout) if sel.nil? raise TimeoutError,"Timeout (#{@timeout} s) in IO.select" end sel.each do |io| @handler[io].process_line end if @timeout && @hb_earliest if Time.now - @hb_earliest > @timeout io = @hb_time.key(@hb_earliest) raise TimeoutError,"Timeout (#{@timeout}s) "+ "in Heartbeat from host=#{get_host(io)}" end end end end |