Sha256: 0344cf26efdeb82cb994ae03bc325b7cd86499d926513a79f4282cba402f9907

Contents?: true

Size: 1.22 KB

Versions: 2

Compression:

Stored size: 1.22 KB

Contents

require 'hashie'
require 'net/ssh'

module Supervisor
  class Server
    attr_accessor :name,:host,:rails_path,:connection
    @@instance_collector = []
    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

    def self.servers
      return @@instance_collector
    end

    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
    
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
supervisor-0.0.96 lib/supervisor/server.rb
supervisor-0.0.95 lib/supervisor/server.rb