Class: Actions::Pulp3::AbstractAsyncTask

Inherits:
Abstract
  • Object
show all
Includes:
Base::Polling, Dynflow::Action::Cancellable
Defined in:
app/lib/actions/pulp3/abstract_async_task.rb

Instance Method Summary collapse

Methods inherited from Abstract

#smart_proxy

Instance Method Details

#cancelObject



81
82
83
84
# File 'app/lib/actions/pulp3/abstract_async_task.rb', line 81

def cancel
  pulp_tasks.each { |task| task.cancel }
  task_groups.each { |task_group| task_group.cancel }
end

#cancel!Object



73
74
75
76
77
78
79
# File 'app/lib/actions/pulp3/abstract_async_task.rb', line 73

def cancel!
  cancel
  poll_external_task
  # We suspend the action and the polling will take care of finding
  # out if the cancelling was successful
  suspend unless done?
end

#combined_tasksObject



48
49
50
51
# File 'app/lib/actions/pulp3/abstract_async_task.rb', line 48

def combined_tasks
  return nil if pulp_tasks.nil? && task_groups.nil?
  pulp_tasks + task_groups
end

#done?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'app/lib/actions/pulp3/abstract_async_task.rb', line 39

def done?
  combined_tasks&.all? { |task| task.done? }
end

#external_taskObject



43
44
45
46
# File 'app/lib/actions/pulp3/abstract_async_task.rb', line 43

def external_task
  #this must return nil until external_task= is called
  combined_tasks
end

#humanized_stateObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/lib/actions/pulp3/abstract_async_task.rb', line 14

def humanized_state
  case state
  when :running
    if self.combined_tasks.empty?
      _("initiating Pulp task")
    else
      _("checking Pulp task status")
    end
  when :suspended
    started_task = combined_tasks.find { |task| task&.started? && !task&.done? }&.pulp_data
    if started_task
      name = started_task[:name] || started_task[:description]
      label = get_task_label(name, started_task[:pulp_href])
      _("waiting for Pulp to finish the task %s" % label)
    else
      pending_task = combined_tasks.find { |task| !task&.started? }&.pulp_data
      name = pending_task[:name] || pending_task[:description]
      label = get_task_label(name, pending_task[:pulp_href])
      _("waiting for Pulp to start the task %s" % label) if pending_task
    end
  else
    super
  end
end

#new_or_existing_objects(object_class, objects) ⇒ Object



63
64
65
66
67
68
69
70
71
# File 'app/lib/actions/pulp3/abstract_async_task.rb', line 63

def new_or_existing_objects(object_class, objects)
  objects.map do |object|
    if object.is_a?(object_class)
      object
    else
      object_class.new(smart_proxy, object)
    end
  end
end

#pulp_tasksObject



53
54
55
56
# File 'app/lib/actions/pulp3/abstract_async_task.rb', line 53

def pulp_tasks
  return nil if output[:pulp_tasks].nil?
  output[:pulp_tasks] = new_or_existing_objects(::Katello::Pulp3::Task, output[:pulp_tasks])
end

#rescue_external_task(error) ⇒ Object



86
87
88
89
90
91
92
# File 'app/lib/actions/pulp3/abstract_async_task.rb', line 86

def rescue_external_task(error)
  if error.is_a?(::Katello::Errors::Pulp3Error)
    fail error
  else
    super
  end
end

#run(event = nil) ⇒ Object



7
8
9
10
11
12
# File 'app/lib/actions/pulp3/abstract_async_task.rb', line 7

def run(event = nil)
  # do nothing when the action is being skipped
  unless event == Dynflow::Action::Skip
    super
  end
end

#task_groupsObject



58
59
60
61
# File 'app/lib/actions/pulp3/abstract_async_task.rb', line 58

def task_groups
  return nil if output[:task_groups].nil?
  output[:task_groups] = new_or_existing_objects(::Katello::Pulp3::TaskGroup, output[:task_groups])
end