Class: RbVmomi::VIM::Task

Inherits:
Object
  • Object
show all
Defined in:
lib/rbvmomi/vim/Task.rb

Instance Method Summary collapse

Instance Method Details

#child_tasksArray

Get child tasks of this task.



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/rbvmomi/vim/Task.rb', line 54

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

#wait_for_childtask_completionHash

Wait for all child tasks to finish. If any one child task failed, the exception of the first failing task is thrown.

Raises:

  • info.error on error.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/rbvmomi/vim/Task.rb', line 19

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_completionObject

Wait for a task to finish.

Raises:

  • info.error on error.



5
6
7
8
9
10
11
12
13
# File 'lib/rbvmomi/vim/Task.rb', line 5

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_progress {|info.progress| ... } ⇒ Object

Wait for a task to finish, with progress notifications.

Yields:

  • (info.progress)

Raises:

  • info.error on error.



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/rbvmomi/vim/Task.rb', line 39

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