diff options
author | Saku Ytti <saku@ytti.fi> | 2014-04-22 12:45:56 +0300 |
---|---|---|
committer | Saku Ytti <saku@ytti.fi> | 2014-04-22 12:45:56 +0300 |
commit | e702fdb9d88e8b6d34f3740de9f10f5e9d3030be (patch) | |
tree | 9bd207bad021d888b8bb14566f9b9270b8662424 /lib | |
parent | 09dfc11b5dfdfe926b217c17549e417b79009d7d (diff) |
more work to fix issue shown in 09dfc11b5dfd
Diffstat (limited to 'lib')
-rw-r--r-- | lib/oxidized/nodes.rb | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/lib/oxidized/nodes.rb b/lib/oxidized/nodes.rb index 4ceee31..465713e 100644 --- a/lib/oxidized/nodes.rb +++ b/lib/oxidized/nodes.rb @@ -61,7 +61,7 @@ module Oxidized # @param node [String] name of the node moved into the head of array def next node, opt={} with_lock do - n = running.del node + n = waiting.del node if n n = del node n.user = opt['user'] @@ -74,6 +74,7 @@ module Oxidized end end alias :top :next + # @return [String] node from the head of the array def get with_lock do @@ -81,24 +82,25 @@ module Oxidized end end - # @return [Array] list of nodes running now - def running - select { |node| node.running? } - end - - # @return [Array] list of nodes waiting (not running) - def waiting - select { |node| not node.running? } + # @param node node which is removed from nodes list + # @return [Node] deleted node + def del node + with_lock do + delete_at find_node_index(node) + end end - private def initialize opts={} super() node = opts.delete :node @mutex= Mutex.new # we compete for the nodes with webapi thread - load node + if nodes = opts.delete :nodes + replace nodes + else + load node + end end def with_lock &block @@ -113,8 +115,15 @@ module Oxidized find_index node or raise Oxidized::NodeNotFound, "unable to find '#{node}'" end - def del node - delete_at find_node_index(node) + # @return [Nodes] list of nodes running now + def running + Nodes.new :nodes => select { |node| node.running? } end + + # @return [Nodes] list of nodes waiting (not running) + def waiting + Nodes.new :nodes => select { |node| not node.running? } + end + end end |