Skip to content

Commit

Permalink
Fixes #48, disabling possibility to save interval=0, never try to div…
Browse files Browse the repository at this point in the history
…ide by zero!
  • Loading branch information
jperelli committed Feb 12, 2017
1 parent e9ce212 commit d45865a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/views/periodictask/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<%= l(:no_members_in_project) %>
<% end %>
</p>
<p><%= label(:periodictask, :interval_number, l(:label_interval)) %><%= f.text_field :interval_number, :required=> true, :size => 3 %> <%= select 'periodictask', 'interval_units', Periodictask::INTERVAL_UNITS %></p>
<p><%= label(:periodictask, :interval_number, l(:label_interval)) %><%= f.number_field :interval_number, :value => 1, :required => true, :min => 1 %> <%= select 'periodictask', 'interval_units', Periodictask::INTERVAL_UNITS %></p>
<p><%= label(:periodictask, :tracker_id, "Tracker") %><%= collection_select("periodictask", "tracker_id", @project.trackers, :id, :name ) %></p>
<p><%= label(:periodictask, :set_start_date, l(:label_set_start_date)) %><%= f.check_box :set_start_date %> </p>
<p><%= label(:periodictask, :due_date, l(:label_due_date)) %><%= f.text_field :due_date_number, :size => 3 %><%= select 'periodictask', 'due_date_units', Periodictask::INTERVAL_UNITS %></p>
Expand Down
6 changes: 4 additions & 2 deletions lib/scheduled_tasks_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ def self.checktasks!
if units.downcase == "business_day"
task.next_run_date = task.interval_number.business_day.after(now)
else
interval_steps = ((now - task.next_run_date) / interval.send(unit_to_use)).ceil
task.next_run_date += (interval * interval_steps).send(units.downcase)
if (interval > 0)
interval_steps = ((now - task.next_run_date) / interval.send(units.downcase)).ceil
task.next_run_date += (interval * interval_steps).send(units.downcase)
end
end
task.save
end
Expand Down

0 comments on commit d45865a

Please sign in to comment.