class Heroku::Client::Service

Attributes

attached[RW]

Public Class Methods

new(client, app) click to toggle source
# File lib/heroku/client.rb, line 351
def initialize(client, app)
  require 'rest_client'
  @client = client
  @app = app
end

Public Instance Methods

each() { |output| ... } click to toggle source

Iterate over all output chunks until EOF is reached.

# File lib/heroku/client.rb, line 398
def each
  until end_of_stream?
    sleep(@interval)
    output = read
    yield output unless output.empty?
  end
end
end_of_stream?() click to toggle source

Does the service have any remaining output?

# File lib/heroku/client.rb, line 374
def end_of_stream?
  @next_chunk.nil?
end
read() click to toggle source

Read the next chunk of output.

# File lib/heroku/client.rb, line 379
def read
  chunk = @client.get(@next_chunk)
  if chunk.headers[:location].nil? && chunk.code != 204
    # no more chunks
    @next_chunk = nil
    chunk.to_s
  elsif chunk.to_s == ''
    # assume no content and back off
    @interval = 2
    ''
  elsif location = chunk.headers[:location]
    # some data read and next chunk available
    @next_chunk = location
    @interval = 0
    chunk.to_s
  end
end
start(command, attached=false) click to toggle source

start the service

# File lib/heroku/client.rb, line 358
def start(command, attached=false)
  @attached = attached
  @response = @client.post(
    "/apps/#{@app}/services",
    command,
    :content_type => 'text/plain'
  )
  @next_chunk = @response.to_s
  @interval = 0
  self
rescue RestClient::RequestFailed => e
  raise AppCrashed, e.http_body  if e.http_code == 502
  raise
end
to_s() click to toggle source

All output as a string

# File lib/heroku/client.rb, line 407
def to_s
  buf = []
  each { |part| buf << part }
  buf.join
end