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.
-
#upid ⇒ Object
Returns the value of attribute upid.
Instance Method Summary collapse
- #bounce ⇒ Object
- #down ⇒ Object
-
#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, upid = nil) ⇒ 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.
- #transition(action) ⇒ Object
- #up ⇒ Object
Constructor Details
#initialize(client, app, upid = nil) ⇒ Service
Returns a new instance of Service.
201 202 203 204 205 |
# File 'lib/heroku/client.rb', line 201 def initialize(client, app, upid=nil) @client = client @app = app @upid = upid end |
Instance Attribute Details
#attached ⇒ Object
Returns the value of attribute attached.
199 200 201 |
# File 'lib/heroku/client.rb', line 199 def attached @attached end |
#upid ⇒ Object
Returns the value of attribute upid.
199 200 201 |
# File 'lib/heroku/client.rb', line 199 def upid @upid end |
Instance Method Details
#bounce ⇒ Object
237 |
# File 'lib/heroku/client.rb', line 237 def bounce ; transition('bounce') ; end |
#down ⇒ Object
235 |
# File 'lib/heroku/client.rb', line 235 def down ; transition('down') ; end |
#each ⇒ Object
Iterate over all output chunks until EOF is reached.
264 265 266 267 268 269 270 |
# File 'lib/heroku/client.rb', line 264 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?
240 241 242 |
# File 'lib/heroku/client.rb', line 240 def end_of_stream? @next_chunk.nil? end |
#read ⇒ Object
Read the next chunk of output.
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
# File 'lib/heroku/client.rb', line 245 def read chunk = @client.get(@next_chunk) if chunk.nil? or chunk == '' # 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 else # no more chunks @next_chunk = nil chunk end end |
#start(command, attached = false) ⇒ Object
start the service
208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/heroku/client.rb', line 208 def start(command, attached=false) @attached = attached @response = @client.post( "/apps/#{@app}/services", command, :content_type => 'text/plain' ) @next_chunk = @response @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
273 274 275 276 277 |
# File 'lib/heroku/client.rb', line 273 def to_s buf = [] each { |part| buf << part } buf.join end |
#transition(action) ⇒ Object
223 224 225 226 227 228 229 230 231 232 233 |
# File 'lib/heroku/client.rb', line 223 def transition(action) @response = @client.put( "/apps/#{@app}/services/#{@upid}", action, :content_type => 'text/plain' ) self rescue RestClient::RequestFailed => e raise AppCrashed, e.http_body if e.http_code == 502 raise end |
#up ⇒ Object
236 |
# File 'lib/heroku/client.rb', line 236 def up ; transition('up') ; end |