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, #coin, #config, #devdetails, #devs, #notify, #pga, #pgacount, #pools, #privileged, #stats, #summary, #usbstats, #version

Constructor Details

#initialize(on_wire: nil) ⇒ MinerPool

Returns a new instance of MinerPool.



9
10
11
12
# File 'lib/cgminer_api_client/miner_pool.rb', line 9

def initialize(on_wire: nil)
  @on_wire = on_wire
  load_miners!
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name) ⇒ Object



82
83
84
# File 'lib/cgminer_api_client/miner_pool.rb', line 82

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

Instance Attribute Details

#minersObject

Returns the value of attribute miners.



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

def miners
  @miners
end

Instance Method Details

#available_minersObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/cgminer_api_client/miner_pool.rb', line 56

def available_miners
  threads = @miners.map do |miner|
    Thread.new do
      # Suppress Ruby's default "auto-print unhandled thread
      # exceptions to stderr" behavior. Bugs that propagate
      # here will be re-raised by Thread#value to the caller of
      # #available_miners; we don't want them double-reported
      # to stderr in the meantime.
      Thread.current.report_on_exception = false
      miner if miner.available?
    rescue SocketError, SystemCallError, CgminerApiClient::TimeoutError
      # Miner#available? already returns false for these; this
      # rescue is defensive against a future refactor. Bugs
      # (NoMethodError, ArgumentError) still propagate via
      # Thread#value re-raising.
      nil
    end
  end
  threads.each(&:join)
  threads.map(&:value).compact
end

#check(command) ⇒ Object



52
53
54
# File 'lib/cgminer_api_client/miner_pool.rb', line 52

def check(command)
  unwrap_first(query(:check, command))
end

#query(method, *params) ⇒ Object

Runs ‘method` against every miner in the pool in parallel and returns a PoolResult — an Enumerable wrapper around a MinerResult per miner, in pool order. Successes and failures are both captured structurally; this method does NOT write to stderr. Callers that want to display failures should iterate the result (or use PoolResult#errors).



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/cgminer_api_client/miner_pool.rb', line 25

def query(method, *params)
  threads = @miners.map do |miner|
    Thread.new do
      MinerResult.success(miner, miner.query(method, *params))
    rescue StandardError => e
      MinerResult.failure(miner, e)
    end
  end
  threads.each(&:join)
  PoolResult.new(threads.map(&:value))
end

#reload_miners!Object



14
15
16
17
# File 'lib/cgminer_api_client/miner_pool.rb', line 14

def reload_miners!
  @miners = nil
  load_miners!
end

#respond_to_missing?(name, _include_private = false) ⇒ Boolean

See Miner#respond_to_missing? for the rationale.

Returns:

  • (Boolean)


87
88
89
# File 'lib/cgminer_api_client/miner_pool.rb', line 87

def respond_to_missing?(name, _include_private = false)
  !name.to_s.start_with?('to_', '_')
end

#unavailable_minersObject



78
79
80
# File 'lib/cgminer_api_client/miner_pool.rb', line 78

def unavailable_miners
  @miners - available_miners
end