Class: Heroku::Commander

Inherits:
Object
  • Object
show all
Defined in:
lib/heroku/commander.rb,
lib/heroku/commander/version.rb,
lib/heroku/commander/errors/base.rb,
lib/heroku/commander/errors/command_error.rb,
lib/heroku/commander/errors/client_eio_error.rb,
lib/heroku/commander/errors/missing_pid_error.rb,
lib/heroku/commander/errors/invalid_option_error.rb,
lib/heroku/commander/errors/already_running_error.rb,
lib/heroku/commander/errors/missing_command_error.rb,
lib/heroku/commander/errors/no_such_process_error.rb,
lib/heroku/commander/errors/unexpected_output_error.rb

Defined Under Namespace

Modules: Errors

Constant Summary collapse

VERSION =
'0.3.1'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Commander

Returns a new instance of Commander.



6
7
8
9
# File 'lib/heroku/commander.rb', line 6

def initialize(options = {})
  @app = options[:app]
  @logger = options[:logger]
end

Instance Attribute Details

#appObject

Returns the value of attribute app.



4
5
6
# File 'lib/heroku/commander.rb', line 4

def app
  @app
end

#configObject

Returns a loaded Heroku::Config instance.



12
13
14
# File 'lib/heroku/commander.rb', line 12

def config
  @config
end

#loggerObject

Returns the value of attribute logger.



4
5
6
# File 'lib/heroku/commander.rb', line 4

def logger
  @logger
end

Instance Method Details

#processes(&block) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/heroku/commander.rb', line 18

def processes(&block)
  processes = []
  cmdline = [ "heroku", "ps", @app ? "--app #{@app}" : nil ].compact.join(" ")
  Heroku::Executor.run cmdline, { :logger => logger } do |line|
    next if ! line || line[0] == '=' || line.length == 0
    if (match = line.match /(\w+\.\d+): (\w+)/)
      process = Heroku::Process.new({ :logger => logger, :pid => match[1], :status => match[2], :app => app })
      processes << process
      logger.info "Process: #{process.pid} (#{process.status}) from '#{line}'" if logger
      yield process if block_given?
    else
      logger.warn "Unexpected line from heroku ps: #{line}" if logger
    end
  end
  processes
end

#run(command, options = {}, &block) ⇒ Object

Run a process synchronously



36
37
38
39
40
# File 'lib/heroku/commander.rb', line 36

def run(command, options = {}, &block)
  size = options.delete(:size) if options
  runner = Heroku::Runner.new({ :app => app, :logger => logger, :command => command, size: size })
  runner.run!(options, &block)
end