Class: Actions::EntryAction

Inherits:
Base
  • Object
show all
Includes:
Helpers::ArgsSerialization, Helpers::Lock
Defined in:
app/lib/actions/entry_action.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers::Lock

#exclusive_lock!, #link!, #lock!

Methods included from Helpers::ArgsSerialization

#serialize_args

Methods inherited from Base

#already_running?, #humanized_errors, #humanized_output, #notify_paused, #serializer_class, #task, #task_input, #task_output

Methods included from TaskSynchronization

included, #sync_execution_plan_to_task

Methods included from Helpers::LifecycleLogging

included, #log_task_state_change

Class Method Details

.all_action_namesObject



55
56
57
# File 'app/lib/actions/entry_action.rb', line 55

def self.all_action_names
  subclasses.map { |k| k.allocate.humanized_name }
end

.serializer_classObject



63
64
65
# File 'app/lib/actions/entry_action.rb', line 63

def self.serializer_class
  Serializers::ActiveRecordSerializer
end

Instance Method Details

#action_subject(resource, *additional_args) ⇒ Object

Performs all that’s needed to connect the action to the resource. It converts the resource (and it’s relatives defined in related_resources to serialized form (using to_action_input).

It also locks the resource on the actions defined in resource_locks method.

The additional args can include more resources and/or a hash with more data describing the action that should appear in the action’s input. TODO redo as a middleware



34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/lib/actions/entry_action.rb', line 34

def action_subject(resource, *additional_args)
  Type! resource, ForemanTasks::Concerns::ActionSubject
  input.update serialize_args(resource, *resource.all_related_resources, *additional_args)

  if resource.is_a? ActiveRecord::Base
    if resource_locks == :link
      link!(resource)
    else
      exclusive_lock!(resource)
    end
  end
end

#delay(_schedule_options, *args) ⇒ Object



59
60
61
# File 'app/lib/actions/entry_action.rb', line 59

def delay(_schedule_options, *args)
  serializer_class.new args
end

#drop_all_locks!(_execution_plan) ⇒ Object



67
68
69
# File 'app/lib/actions/entry_action.rb', line 67

def drop_all_locks!(_execution_plan)
  ForemanTasks::Lock.where(:task_id => task.id).destroy_all
end

#humanized_inputObject



47
48
49
# File 'app/lib/actions/entry_action.rb', line 47

def humanized_input
  Helpers::Humanizer.new(self).input
end

#humanized_nameObject



51
52
53
# File 'app/lib/actions/entry_action.rb', line 51

def humanized_name
  _(super)
end

#resource_locksObject

what locks to use on the resource? All by default, can be overriden. It might one or more locks available for the resource. This following special values are supported as well:

* `:all`:        lock all possible operations (all locks defined in resource's
                 `available_locks` method. Only tasks that link to the resource are
                 allowed while running this task
* `:exclusive`:  same as `:all` + doesn't allow even linking to the resoruce.
                 typical example is deleting a container, preventing all actions
                 heppening on it's sub-resources (such a system).
* `:link`:       only link the task to the resource, not locking
                 anything except exclusive locks


20
21
22
# File 'app/lib/actions/entry_action.rb', line 20

def resource_locks
  :all
end