Class: Pwrake::HostInfo
- Inherits:
-
Object
- Object
- Pwrake::HostInfo
- Defined in:
- lib/pwrake/option/host_map.rb
Constant Summary collapse
- @@local_ip =
nil
Instance Attribute Summary collapse
-
#continuous_fail ⇒ Object
readonly
Returns the value of attribute continuous_fail.
-
#group ⇒ Object
readonly
Returns the value of attribute group.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#idle_cores ⇒ Object
Returns the value of attribute idle_cores.
-
#ipaddr ⇒ Object
readonly
Returns the value of attribute ipaddr.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#ncore ⇒ Object
readonly
Returns the value of attribute ncore.
-
#steal_flag ⇒ Object
readonly
Returns the value of attribute steal_flag.
-
#weight ⇒ Object
readonly
Returns the value of attribute weight.
Class Method Summary collapse
Instance Method Summary collapse
- #accept_core(use_cores) ⇒ Object
- #add_line(ncore = nil, weight = nil, group = nil) ⇒ Object
- #busy(n) ⇒ Object
- #count_result(result) ⇒ Object
- #idle(n) ⇒ Object
-
#initialize(name, id, ncore, weight, group = nil) ⇒ HostInfo
constructor
A new instance of HostInfo.
- #local? ⇒ Boolean
- #retire(n) ⇒ Object
- #retired? ⇒ Boolean
- #set_ip(ipa) ⇒ Object
- #set_ncore(n) ⇒ Object
- #steal_phase ⇒ Object
Constructor Details
#initialize(name, id, ncore, weight, group = nil) ⇒ HostInfo
Returns a new instance of HostInfo.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/pwrake/option/host_map.rb', line 14 def initialize(name,id,ncore,weight,group=nil) @name = name @ncore = ncore || 1 @weight = weight || 1.0 @group = group || 0 @id = id @continuous_fail = 0 @total_fail = 0 @count_task = 0 @ipaddr = [] begin @ipaddr << IPSocket.getaddress(@name) rescue end end |
Instance Attribute Details
#continuous_fail ⇒ Object (readonly)
Returns the value of attribute continuous_fail.
32 33 34 |
# File 'lib/pwrake/option/host_map.rb', line 32 def continuous_fail @continuous_fail end |
#group ⇒ Object (readonly)
Returns the value of attribute group.
30 31 32 |
# File 'lib/pwrake/option/host_map.rb', line 30 def group @group end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
30 31 32 |
# File 'lib/pwrake/option/host_map.rb', line 30 def id @id end |
#idle_cores ⇒ Object
Returns the value of attribute idle_cores.
33 34 35 |
# File 'lib/pwrake/option/host_map.rb', line 33 def idle_cores @idle_cores end |
#ipaddr ⇒ Object (readonly)
Returns the value of attribute ipaddr.
31 32 33 |
# File 'lib/pwrake/option/host_map.rb', line 31 def ipaddr @ipaddr end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
30 31 32 |
# File 'lib/pwrake/option/host_map.rb', line 30 def name @name end |
#ncore ⇒ Object (readonly)
Returns the value of attribute ncore.
30 31 32 |
# File 'lib/pwrake/option/host_map.rb', line 30 def ncore @ncore end |
#steal_flag ⇒ Object (readonly)
Returns the value of attribute steal_flag.
30 31 32 |
# File 'lib/pwrake/option/host_map.rb', line 30 def steal_flag @steal_flag end |
#weight ⇒ Object (readonly)
Returns the value of attribute weight.
30 31 32 |
# File 'lib/pwrake/option/host_map.rb', line 30 def weight @weight end |
Class Method Details
.local_ip ⇒ Object
9 10 11 12 |
# File 'lib/pwrake/option/host_map.rb', line 9 def self.local_ip @@local_ip ||= Socket.getifaddrs.select{|a| a.addr.ip?}.map{|a| a.addr.ip_address} end |
Instance Method Details
#accept_core(use_cores) ⇒ Object
99 100 101 |
# File 'lib/pwrake/option/host_map.rb', line 99 def accept_core(use_cores) use_cores <= @idle_cores end |
#add_line(ncore = nil, weight = nil, group = nil) ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/pwrake/option/host_map.rb', line 35 def add_line(ncore=nil,weight=nil,group=nil) ncore ||= 1 weight ||= 1.0 group ||= 0 if @group != group raise "different group=#{group} for host=#{@name}" end @weight = (@weight*@ncore + weight*ncore)/(@ncore+ncore) @ncore += ncore end |
#busy(n) ⇒ Object
65 66 67 68 |
# File 'lib/pwrake/option/host_map.rb', line 65 def busy(n) @busy_cores += n @idle_cores -= n end |
#count_result(result) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/pwrake/option/host_map.rb', line 85 def count_result(result) @count_task += 1 case result when "end" @continuous_fail = 0 when "fail" @continuous_fail += 1 @total_fail += 1 else raise "unknown result: #{result}" end @continuous_fail end |
#idle(n) ⇒ Object
60 61 62 63 |
# File 'lib/pwrake/option/host_map.rb', line 60 def idle(n) @busy_cores -= n @idle_cores += n end |
#local? ⇒ Boolean
46 47 48 49 |
# File 'lib/pwrake/option/host_map.rb', line 46 def local? ipa = IPSocket.getaddress(@name) HostInfo.local_ip.include?(ipa) end |
#retire(n) ⇒ Object
70 71 72 |
# File 'lib/pwrake/option/host_map.rb', line 70 def retire(n) @idle_cores -= n end |
#retired? ⇒ Boolean
74 75 76 |
# File 'lib/pwrake/option/host_map.rb', line 74 def retired? @idle_cores + @busy_cores < 1 # all retired end |
#set_ip(ipa) ⇒ Object
56 57 58 |
# File 'lib/pwrake/option/host_map.rb', line 56 def set_ip(ipa) @ipaddr.push(ipa) end |
#set_ncore(n) ⇒ Object
51 52 53 54 |
# File 'lib/pwrake/option/host_map.rb', line 51 def set_ncore(n) @busy_cores = 0 @ncore = @idle_cores = n end |
#steal_phase ⇒ Object
78 79 80 81 82 83 |
# File 'lib/pwrake/option/host_map.rb', line 78 def steal_phase @steal_flag = true t = yield(self) @steal_flag = false t end |