From e702fdb9d88e8b6d34f3740de9f10f5e9d3030be Mon Sep 17 00:00:00 2001 From: Saku Ytti Date: Tue, 22 Apr 2014 12:45:56 +0300 Subject: more work to fix issue shown in 09dfc11b5dfd --- lib/oxidized/nodes.rb | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) (limited to 'lib/oxidized') 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 -- cgit v1.2.1