class Heroku::Client::Service

Attributes

attached[RW]
upid[RW]

Public Class Methods

new(client, app, upid=nil) click to toggle source
# File lib/heroku/client.rb, line 252
def initialize(client, app, upid=nil)
  @client = client
  @app = app
  @upid = upid
end

Public Instance Methods

bounce() click to toggle source
# File lib/heroku/client.rb, line 288
def bounce ; transition('bounce') ; end
down() click to toggle source
# File lib/heroku/client.rb, line 286
def down   ; transition('down') ; end
each() { |output| ... } click to toggle source

Iterate over all output chunks until EOF is reached.

# File lib/heroku/client.rb, line 315
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 291
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 296
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 259
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 324
def to_s
  buf = []
  each { |part| buf << part }
  buf.join
end
transition(action) click to toggle source
# File lib/heroku/client.rb, line 274
def transition(action)
  @response = @client.put(
    "/apps/#{@app}/services/#{@upid}",
    action,
    :content_type => 'text/plain'
  ).to_s
  self
rescue RestClient::RequestFailed => e
  raise AppCrashed, e.http_body  if e.http_code == 502
  raise
end
up() click to toggle source
# File lib/heroku/client.rb, line 287
def up     ; transition('up')   ; end