Remove less_than_1_hour_from_now comments. Dry up def schedule_next_run!

This commit is contained in:
Shinya Maeda 2017-04-04 16:58:02 +09:00
parent a67aff6d39
commit f6be8c0485
1 changed files with 1 additions and 21 deletions

View File

@ -14,32 +14,12 @@ module Ci
validates :cron, cron: true, presence: { unless: :importing? }
validates :cron_time_zone, presence: { unless: :importing? }
validates :ref, presence: { unless: :importing? }
# validate :check_cron_frequency
after_create :schedule_next_run!
def schedule_next_run!
next_time = Ci::CronParser.new(cron, cron_time_zone).next_time_from(Time.now)
# if next_time.present? && !less_than_1_hour_from_now?(next_time)
if next_time.present?
update!(next_run_at: next_time)
end
update!(next_run_at: next_time) if next_time.present?
end
# private
# def less_than_1_hour_from_now?(time)
# puts "diff: #{(time - Time.now).abs.inspect}"
# ((time - Time.now).abs < 1.hour) ? true : false
# end
# def check_cron_frequency
# next_time = Ci::CronParser.new(cron, cron_time_zone).next_time_from(Time.now)
# if less_than_1_hour_from_now?(next_time)
# self.errors.add(:cron, " can not be less than 1 hour")
# end
# end
end
end