Class: Heroku::Client::Service
- Inherits:
-
Object
- Object
- Heroku::Client::Service
- Defined in:
- lib/heroku/client.rb
Instance Attribute Summary collapse
-
#attached ⇒ Object
Returns the value of attribute attached.
Instance Method Summary collapse
-
#each ⇒ Object
Iterate over all output chunks until EOF is reached.
-
#end_of_stream? ⇒ Boolean
Does the service have any remaining output?.
-
#initialize(client, app) ⇒ Service
constructor
A new instance of Service.
-
#read ⇒ Object
Read the next chunk of output.
-
#start(command, attached = false) ⇒ Object
start the service.
-
#to_s ⇒ Object
All output as a string.
Constructor Details
#initialize(client, app) ⇒ Service
Returns a new instance of Service.
351 352 353 354 355 |
# File 'lib/heroku/client.rb', line 351 def initialize(client, app) require 'rest_client' @client = client @app = app end |
Instance Attribute Details
#attached ⇒ Object
Returns the value of attribute attached.
349 350 351 |
# File 'lib/heroku/client.rb', line 349 def attached @attached end |
Instance Method Details
#each ⇒ Object
Iterate over all output chunks until EOF is reached.
398 399 400 401 402 403 404 |
# 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? ⇒ Boolean
Does the service have any remaining output?
374 375 376 |
# File 'lib/heroku/client.rb', line 374 def end_of_stream? @next_chunk.nil? end |
#read ⇒ Object
Read the next chunk of output.
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 |
# 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) ⇒ Object
start the service
358 359 360 361 362 363 364 365 366 367 368 369 370 371 |
# 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 ⇒ Object
All output as a string
407 408 409 410 411 |
# File 'lib/heroku/client.rb', line 407 def to_s buf = [] each { |part| buf << part } buf.join end |