Allow configuration of task periods
This commit is contained in:
parent
6e990fed4c
commit
f6c008c79c
7 changed files with 43 additions and 10 deletions
|
|
@ -1,8 +1,6 @@
|
|||
class PeriodicTaskGroup < ActiveRecord::Base
|
||||
has_many :tasks, dependent: :destroy
|
||||
|
||||
PeriodDays = 7
|
||||
|
||||
def has_next_task?
|
||||
return false if tasks.empty?
|
||||
return false if tasks.first.due_date.nil?
|
||||
|
|
@ -11,13 +9,13 @@ class PeriodicTaskGroup < ActiveRecord::Base
|
|||
|
||||
def create_next_task
|
||||
template_task = tasks.first
|
||||
self.next_task_date ||= template_task.due_date + PeriodDays
|
||||
self.next_task_date ||= template_task.due_date + period_days
|
||||
|
||||
next_task = template_task.dup
|
||||
next_task.due_date = next_task_date
|
||||
next_task.save
|
||||
|
||||
self.next_task_date += PeriodDays
|
||||
self.next_task_date += period_days
|
||||
self.save
|
||||
end
|
||||
|
||||
|
|
@ -26,4 +24,12 @@ class PeriodicTaskGroup < ActiveRecord::Base
|
|||
t.update_attribute(:periodic_task_group, nil)
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
# @return [Number] Number of days between two periodic tasks
|
||||
def period_days
|
||||
# minimum of one to avoid inifite loop when value is invalid
|
||||
[FoodsoftConfig[:tasks_period_days].to_i, 1].max
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue