Class: Buble::AppGenerationsResource
- Inherits:
-
Object
- Object
- Buble::AppGenerationsResource
- Defined in:
- lib/buble/apps.rb
Constant Summary collapse
- TERMINAL_STATUSES =
GenerationsResource::TERMINAL_STATUSES
Instance Method Summary collapse
- #create(app_id, params = {}) ⇒ Object
-
#initialize(http) ⇒ AppGenerationsResource
constructor
A new instance of AppGenerationsResource.
- #retrieve(app_id, id) ⇒ Object
- #wait(app_id, id, interval: 2, timeout: 600, throw_on_failed: true, throw_on_canceled: true) ⇒ Object
Constructor Details
#initialize(http) ⇒ AppGenerationsResource
Returns a new instance of AppGenerationsResource.
7 8 9 |
# File 'lib/buble/apps.rb', line 7 def initialize(http) @http = http end |
Instance Method Details
#create(app_id, params = {}) ⇒ Object
11 12 13 |
# File 'lib/buble/apps.rb', line 11 def create(app_id, params = {}) @http.request('POST', "/api/v1/apps/#{HTTP.encode_segment(app_id)}/generations", body: params) end |
#retrieve(app_id, id) ⇒ Object
15 16 17 |
# File 'lib/buble/apps.rb', line 15 def retrieve(app_id, id) @http.request('GET', "/api/v1/apps/#{HTTP.encode_segment(app_id)}/generations/#{HTTP.encode_segment(id)}") end |
#wait(app_id, id, interval: 2, timeout: 600, throw_on_failed: true, throw_on_canceled: true) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/buble/apps.rb', line 19 def wait(app_id, id, interval: 2, timeout: 600, throw_on_failed: true, throw_on_canceled: true) deadline = Time.now + timeout loop do envelope = retrieve(app_id, id) task = envelope['data'] || {} status = task['status'] if TERMINAL_STATUSES.include?(status) raise_if_terminal_error!(id, task, status, throw_on_failed, throw_on_canceled) return envelope end if Time.now >= deadline raise TimeoutError.new( "App generation #{id} did not finish within #{timeout} seconds.", timeout: timeout ) end sleep interval end end |