Class: CgminerApiClient::MinerPool

Inherits:
Object
  • Object
show all
Includes:
CgminerApiClient::Miner::Commands
Defined in:
lib/cgminer_api_client/miner_pool.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from CgminerApiClient::Miner::Commands::Privileged::System

#debug, #failover_only, #hotplug, #quit, #restart, #save, #setconfig, #zero

Methods included from CgminerApiClient::Miner::Commands::Privileged::Pool

#addpool, #disablepool, #enablepool, #poolpriority, #poolquota, #removepool, #switchpool

Methods included from CgminerApiClient::Miner::Commands::Privileged::Pga

#pgadisable, #pgaenable, #pgaidentify, #pgaset

Methods included from CgminerApiClient::Miner::Commands::Privileged::Asc

#ascdisable, #ascenable, #ascidentify, #ascset

Methods included from CgminerApiClient::Miner::Commands::ReadOnly

#asc, #asccount, #check, #coin, #config, #devdetails, #devs, #notify, #pga, #pgacount, #pools, #privileged, #stats, #summary, #usbstats, #version

Constructor Details

#initializeMinerPool

Returns a new instance of MinerPool.



7
8
9
# File 'lib/cgminer_api_client/miner_pool.rb', line 7

def initialize
  load_miners!
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



49
50
51
# File 'lib/cgminer_api_client/miner_pool.rb', line 49

def method_missing(name, *args)
  query(name, *args)
end

Instance Attribute Details

#minersObject

Returns the value of attribute miners.



5
6
7
# File 'lib/cgminer_api_client/miner_pool.rb', line 5

def miners
  @miners
end

Instance Method Details

#available_miners(force_reload = false) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/cgminer_api_client/miner_pool.rb', line 31

def available_miners(force_reload = false)
  threads = @miners.collect do |miner|
    Thread.new do
      begin
        miner if miner.available?(force_reload)
      rescue
        nil
      end
    end
  end
  threads.each { |thr| thr.join }
  threads.collect(&:value).compact
end

#query(method, *params) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/cgminer_api_client/miner_pool.rb', line 16

def query(method, *params)
  threads = @miners.collect do |miner|
    Thread.new do
      begin
        miner.query(method, *params)
      rescue => e
        $stderr.puts "#{e.class}: #{e}"
        []
      end
    end
  end
  threads.each { |thr| thr.join }
  threads.collect(&:value)
end

#reload_miners!Object



11
12
13
14
# File 'lib/cgminer_api_client/miner_pool.rb', line 11

def reload_miners!
  @miners = nil
  load_miners!
end

#unavailable_miners(force_reload = false) ⇒ Object



45
46
47
# File 'lib/cgminer_api_client/miner_pool.rb', line 45

def unavailable_miners(force_reload = false)
  @miners - available_miners(force_reload)
end