Class: Supervisor::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/supervisor/server.rb

Constant Summary collapse

@@instance_collector =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = "default", host = "localhost", rails_path = nil, username = nil, password = nil) ⇒ Server

Returns a new instance of Server.



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/supervisor/server.rb', line 8

def initialize(name="default",host="localhost",rails_path=nil,username=nil,password=nil)
  unless host == "localhost"
    p host
    @connection = Net::SSH.start(host,username,:password=>password)
    @username = username
  else
    @connection = nil
  end
  @rails_path = rails_path
  @name = name
  @host = host
  @@instance_collector << self
end

Instance Attribute Details

#connectionObject

Returns the value of attribute connection.



6
7
8
# File 'lib/supervisor/server.rb', line 6

def connection
  @connection
end

#hostObject

Returns the value of attribute host.



6
7
8
# File 'lib/supervisor/server.rb', line 6

def host
  @host
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/supervisor/server.rb', line 6

def name
  @name
end

#rails_pathObject

Returns the value of attribute rails_path.



6
7
8
# File 'lib/supervisor/server.rb', line 6

def rails_path
  @rails_path
end

Class Method Details

.serversObject



22
23
24
# File 'lib/supervisor/server.rb', line 22

def self.servers
  return @@instance_collector
end

Instance Method Details

#delayed_job_workersObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/supervisor/server.rb', line 26

def delayed_job_workers
  @worker_list = []
  if self.connection
    workers = connection.exec!("ps aux").split(/\n/).map{|x| x.split(/\s+/) if x.split(/\s+/).last.match("job")}.compact
  else
    workers = %x{ps aux}.split(/\n/).map{|x| x.split(/\s+/) if x.split(/\s+/).last.match("job")}.compact
  end
  if workers.any?
    workers.each do |wkr|
      @worker_list << Hashie::Mash.new({:host=>host,:name=>wkr.last,:pid=>wkr[1],:cpu=>wkr[2],:mem=>wkr[3],:started=>wkr[8],:run_time=>wkr[9]})
    end
    return @worker_list
  else
    return nil
  end
end