Class: Actions::ForemanPatch::Cycle::Create

Inherits:
EntryAction
  • Object
show all
Defined in:
app/lib/actions/foreman_patch/cycle/create.rb

Instance Method Summary collapse

Instance Method Details

#cycleObject



47
48
49
# File 'app/lib/actions/foreman_patch/cycle/create.rb', line 47

def cycle
  @cycle ||= ::ForemanPatch::Cycle.find(input[:cycle][:id])
end

#finalizeObject



39
40
41
42
43
44
45
# File 'app/lib/actions/foreman_patch/cycle/create.rb', line 39

def finalize
  plan = ::ForemanPatch::Plan.find(input[:plan][:id])

  ::ForemanTasks.delay(Actions::ForemanPatch::Cycle::Initiate, delay_options, cycle, plan)

  plan.iterate
end

#humanized_nameObject



51
52
53
# File 'app/lib/actions/foreman_patch/cycle/create.rb', line 51

def humanized_name
  _('Create cycle: %s') % input[:plan][:name]
end

#plan(plan) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/lib/actions/foreman_patch/cycle/create.rb', line 10

def plan(plan)
  action_subject(plan)

  cycle = ::ForemanPatch::Cycle.create!(plan.to_params)

  concurrence do
    plan.window_plans.each do |window_plan|
      plan_action(Actions::ForemanPatch::Window::Create, window_plan, cycle)
    end
  end

  plan.start_date = plan.next_cycle_start
  plan.save!

  plan_self(cycle: cycle.to_action_input)
end

#resource_locksObject



6
7
8
# File 'app/lib/actions/foreman_patch/cycle/create.rb', line 6

def resource_locks
  :link
end

#runObject



27
28
29
30
31
32
33
34
35
36
37
# File 'app/lib/actions/foreman_patch/cycle/create.rb', line 27

def run
  output.update(cycle: cycle.to_action_input)

  users = ::User.select { |user| user.receives?(:patch_cycle_planned) }.compact

  begin
    MailNotification[:patch_cycle_planned].deliver(users: users, cycle: cycle) unless users.blank?
  rescue => error
    Rails.logger.error(error)
  end
end