Sha256: 29dcf81ac119d4dff07407710c1ccd55e6ee3f3d4a2b95f54bb384ff9c292d7a
Contents?: true
Size: 947 Bytes
Versions: 21
Compression:
Stored size: 947 Bytes
Contents
class Roqua::Scheduling::Schedule attr_reader :tasks BEGINNING_OF_EVERY_DAY = proc { Time.now.beginning_of_day + 1.day } BEGINNING_OF_EVERY_HOUR = proc { Time.now.beginning_of_hour + 1.hour } def initialize @tasks = {} end def add_task(name, options, &block) @tasks[name] = Roqua::Scheduling::Task.new(name, options, block) end def self.setup @schedule = Roqua::Scheduling::Schedule.new.tap do |new_schedule| yield(new_schedule) new_schedule.initialize_cronjob_table end end def self.current_schedule @schedule ||= Roqua::Scheduling::Schedule.new end def initialize_cronjob_table Roqua::Scheduling::CronJob.where('name NOT IN (?)', tasks.values.map(&:name)).delete_all tasks.each_value do |task| cron_job = Roqua::Scheduling::CronJob.find_or_initialize_by(name: task.name) cron_job.update next_run_at: task.next_run_at unless cron_job.persisted? end end end
Version data entries
21 entries across 21 versions & 1 rubygems