Sha256: 957bb2c0a6a7f8ab450bdf07214f0c5a97a9089b7225ee686c6cbdb395134a76
Contents?: true
Size: 842 Bytes
Versions: 4
Compression:
Stored size: 842 Bytes
Contents
class Kuroko2::JobSuspendSchedule < Kuroko2::ApplicationRecord include Kuroko2::TableNameCustomizable belongs_to :job_definition validates :cron, format: { with: Kuroko2::JobSchedule::CRON_FORMAT }, uniqueness: { scope: :job_definition_id } validate :validate_cron_schedule def suspend_times(time_from, time_to) it = Chrono::Iterator.new(cron, now: time_from - 1) suspend_times = [] loop do next_time = it.next if next_time <= time_to suspend_times << next_time else break end end suspend_times end private def validate_cron_schedule if Kuroko2::JobSchedule::CRON_FORMAT === cron Chrono::Iterator.new(self.cron).next end nil rescue Chrono::Fields::Base::InvalidField => e errors.add(:cron, "has invalid field: #{e.message}") end end
Version data entries
4 entries across 4 versions & 1 rubygems