Class: VCloud::Task

Inherits:
BaseVCloudEntity show all
Includes:
ParsesXml
Defined in:
lib/vcloud/user/task.rb

Overview

Represents an asynchronous operation in vCloud Director

Defined Under Namespace

Modules: Status

Constant Summary collapse

@@completed_statuses =
[Status::SUCCESS, Status::ERROR, Status::CANCELED, Status::ABORTED]

Instance Method Summary collapse

Methods included from ParsesXml

included, #parse_xml

Methods inherited from BaseVCloudEntity

attr_accessor, attr_reader, attr_writer, from_reference, inherited, #initialize, type

Methods included from RestApi

#build_generic_http_opts, #create, #delete, #http_request, #parse_response, #post, #refresh, #update

Constructor Details

This class inherits a constructor from VCloud::BaseVCloudEntity

Instance Method Details

#wait_to_finish(timeout = 60 * 10) { ... } ⇒ Object

Wait until the status of the task is set to indicate that the task has completed

Parameters:

  • timeout (Integer) (defaults to: 60 * 10)

    Timeout in seconds

Yields:

  • Block to run upon completion or the timeout is reached, whichever comes first



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/vcloud/user/task.rb', line 22

def wait_to_finish(timeout = 60 * 10) 
  first_run = true
  Timeout::timeout(timeout) do        
    until @@completed_statuses.include?(self.status)
      sleep 3 if not first_run
      refresh    
      first_run = false
    end
  end
  yield(self) if block_given?
end