Class: ForemanPatch::Plan
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- ForemanPatch::Plan
- Includes:
- ForemanTasks::Concerns::ActionSubject
- Defined in:
- app/models/foreman_patch/plan.rb
Defined Under Namespace
Classes: Jail
Constant Summary collapse
- UNITS =
['days', 'weeks', 'months', 'years'].freeze
- CORRECTIONS =
['weekday', 'last_day', 'last_weekday', 'avoid_weekend'].freeze
Instance Method Summary collapse
- #end_date ⇒ Object
- #frequency ⇒ Object
- #iterate ⇒ Object
- #next_cycle_start ⇒ Object
- #stop ⇒ Object
- #stopped? ⇒ Boolean
- #to_params ⇒ Object
Instance Method Details
#end_date ⇒ Object
26 27 28 |
# File 'app/models/foreman_patch/plan.rb', line 26 def end_date next_cycle_start - 1.day end |
#frequency ⇒ Object
30 31 32 |
# File 'app/models/foreman_patch/plan.rb', line 30 def frequency interval.send(units) end |
#iterate ⇒ Object
50 51 52 53 54 55 56 |
# File 'app/models/foreman_patch/plan.rb', line 50 def iterate count = tasks.where(state: 'scheduled').count if (count < active_count - 1) or active_count == 0 ForemanTasks.async_task(Actions::ForemanPatch::Cycle::Create, self) end end |
#next_cycle_start ⇒ Object
44 45 46 47 48 |
# File 'app/models/foreman_patch/plan.rb', line 44 def next_cycle_start next_date = start_date + frequency next_date = send(correction, next_date) unless correction.blank? next_date end |
#stop ⇒ Object
38 39 40 41 42 |
# File 'app/models/foreman_patch/plan.rb', line 38 def stop self.active_count = 0 save! tasks.active.each(&:cancel) end |
#stopped? ⇒ Boolean
34 35 36 |
# File 'app/models/foreman_patch/plan.rb', line 34 def stopped? active_count == 0 end |
#to_params ⇒ Object
58 59 60 61 62 63 64 |
# File 'app/models/foreman_patch/plan.rb', line 58 def to_params { name: ForemanPatch::CycleNameGenerator.generate(self), start_date: start_date, end_date: next_cycle_start - 1.day, } end |