Class: ServerStatus::HostSet

Inherits:
Object
  • Object
show all
Defined in:
lib/server-status/host_set.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, options, hosts) ⇒ HostSet

Returns a new instance of HostSet.



8
9
10
11
12
# File 'lib/server-status/host_set.rb', line 8

def initialize(config, options, hosts)
  @config  = config
  @options = options
  @hosts   = hosts.map { |host, name| Host.new(config, host, name) }
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



5
6
7
# File 'lib/server-status/host_set.rb', line 5

def config
  @config
end

#hostsObject

Returns the value of attribute hosts.



5
6
7
# File 'lib/server-status/host_set.rb', line 5

def hosts
  @hosts
end

#optionsObject

Returns the value of attribute options.



5
6
7
# File 'lib/server-status/host_set.rb', line 5

def options
  @options
end

Instance Method Details

#fetch_statusesObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/server-status/host_set.rb', line 14

def fetch_statuses
  progress_bar = TTY::ProgressBar.new("Querying hosts [:bar]", total: @hosts.size, clear: true, hide_cursor: true)
  semaphore = Mutex.new
  completed_hosts = 0

  threads = @hosts.map do |host|
    Thread.new do
      host.fetch_status(status_command)
      semaphore.synchronize { progress_bar.advance }
    end
  end

  threads.each(&:join)
end