Sha256: f996809395cb503766809769555989302377fc874dcd809577057ce9a27313a9

Contents?: true

Size: 1.81 KB

Versions: 16

Compression:

Stored size: 1.81 KB

Contents

class RbVmomi::VIM::Task
  # Wait for a task to finish.
  # @return +info.result+ on success.
  # @raise +info.error+ on error.
  def wait_for_completion
    wait_until('info.state') { %w(success error).member? info.state }
    case info.state
    when 'success'
      info.result
    when 'error'
      raise info.error
    end
  end
  
  # Wait for all child tasks to finish. If any one child task failed,
  # the exception of the first failing task is thrown.
  # @return [Hash] Map of tasks to their +info.result+ on success.
  # @raise +info.error+ on error.
  def wait_for_childtask_completion
    si = _connection.serviceInstance
    tasks_props = si.wait_for_multiple_tasks(
      ['info.state', 'info.result', 'info.error'],
      self.child_tasks
    )
    Hash[tasks_props.map do |task, props|
      case props['info.state']
      when 'success'
        [task, props['info.result']]
      when 'error'
        raise props['info.error']
      end
    end]
  end

  # Wait for a task to finish, with progress notifications.
  # @return (see #wait_for_completion)
  # @raise (see #wait_for_completion)
  # @yield [info.progress]
  def wait_for_progress
    wait_until('info.state', 'info.progress') do
      yield info.progress if block_given?
      %w(success error).member? info.state
    end
    case info.state
    when 'success'
      info.result
    when 'error'
      raise info.error
    end
  end
  
  # Get child tasks of this task.
  # @return [Array] List of VIM::Task objects
  def child_tasks
    tm = _connection.serviceContent.taskManager
    col = tm.CreateCollectorForTasks(:filter => {
      :rootTaskKey => [self.info.key],
    })
    # XXX: Likely this is not enough and we need to collect pages other
    #      than the latest.
    tasks = col.latestPage.map{|x| x.task}
    col.DestroyCollector()
    tasks
  end
end

Version data entries

16 entries across 16 versions & 4 rubygems

Version Path
rbvmomi-1.8.5 lib/rbvmomi/vim/Task.rb
rbvmomi-1.8.4 lib/rbvmomi/vim/Task.rb
rbvmomi-1.8.3 lib/rbvmomi/vim/Task.rb
rbvmomi-1.9.4 lib/rbvmomi/vim/Task.rb
rbvmomi-1.9.3 lib/rbvmomi/vim/Task.rb
rbvmomi-1.9.2 lib/rbvmomi/vim/Task.rb
rbvmomi-1.9.1 lib/rbvmomi/vim/Task.rb
rbvmomi-1.9.0 lib/rbvmomi/vim/Task.rb
rbvmomi-1.8.2 lib/rbvmomi/vim/Task.rb
rbvmomi-1.8.2.pre lib/rbvmomi/vim/Task.rb
mkuzmin-rbvmomi-1.8.2.1 lib/rbvmomi/vim/Task.rb
vagrant-rbvmomi-1.8.1 lib/rbvmomi/vim/Task.rb
rbvmomi-1.8.1 lib/rbvmomi/vim/Task.rb
rbvmomi-1.8.0 lib/rbvmomi/vim/Task.rb
gapinc-rbvmomi-1.6.1 lib/rbvmomi/vim/Task.rb
gapinc-rbvmomi-1.6.0 lib/rbvmomi/vim/Task.rb