Class: Actions::ForemanPatch::Round::Patch

Inherits:
ActionWithSubPlans
  • Object
show all
Includes:
Dynflow::Action::WithBulkSubPlans
Defined in:
app/lib/actions/foreman_patch/round/patch.rb

Instance Method Summary collapse

Instance Method Details

#batch(from, size) ⇒ Object



66
67
68
# File 'app/lib/actions/foreman_patch/round/patch.rb', line 66

def batch(from, size)
  invocations.offset(from).limit(size)
end

#check_for_errors!Object



45
46
# File 'app/lib/actions/foreman_patch/round/patch.rb', line 45

def check_for_errors!
end

#create_sub_plansObject



17
18
19
20
21
# File 'app/lib/actions/foreman_patch/round/patch.rb', line 17

def create_sub_plans
  current_batch.map do |invocation|
    trigger(Actions::ForemanPatch::Invocation::Patch, invocation)
  end
end

#humanized_nameObject



74
75
76
# File 'app/lib/actions/foreman_patch/round/patch.rb', line 74

def humanized_name
  'Patch Group: %s' % round.name
end

#initiateObject



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/lib/actions/foreman_patch/round/patch.rb', line 31

def initiate
  round.update!(status: 'running')

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

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

  super
end

#invocationsObject



62
63
64
# File 'app/lib/actions/foreman_patch/round/patch.rb', line 62

def invocations
  round.invocations.order(:id)
end

#on_finishObject



48
49
50
51
52
53
54
55
56
# File 'app/lib/actions/foreman_patch/round/patch.rb', line 48

def on_finish
  round.update!(status: 'complete')

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

  MailNotification[:patch_group_completed].deliver(users: users, group: round) unless users.blank?
rescue => error
  Rails.logger.error(error)
end

#plan(round) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'app/lib/actions/foreman_patch/round/patch.rb', line 7

def plan(round)
  action_subject(round)

  limit_concurrency_level round.max_unavailable unless round.max_unavailable.nil?

  plan_self

  round.update!(status: 'pending')
end

#rescue_strategyObject



23
24
25
# File 'app/lib/actions/foreman_patch/round/patch.rb', line 23

def rescue_strategy
  ::Dynflow::Action::Rescue::Skip
end

#roundObject



58
59
60
# File 'app/lib/actions/foreman_patch/round/patch.rb', line 58

def round
  @round ||= ::ForemanPatch::Round.find(input[:round][:id])
end

#run(event = nil) ⇒ Object



27
28
29
# File 'app/lib/actions/foreman_patch/round/patch.rb', line 27

def run(event = nil)
  super unless event == Dynflow::Action::Skip
end

#total_countObject



70
71
72
# File 'app/lib/actions/foreman_patch/round/patch.rb', line 70

def total_count
  output[:total_count] || invocations.count
end