class Roqua::Scheduling::Schedule

Constants

BEGINNING_OF_EVERY_DAY
BEGINNING_OF_EVERY_HOUR

Attributes

tasks[R]

Public Class Methods

current_schedule() click to toggle source
# File lib/roqua/scheduling/schedule.rb, line 22
def self.current_schedule
  @schedule ||= Roqua::Scheduling::Schedule.new
end
new() click to toggle source
# File lib/roqua/scheduling/schedule.rb, line 7
def initialize
  @tasks = {}
end
setup() { |new_schedule| ... } click to toggle source
# File lib/roqua/scheduling/schedule.rb, line 15
def self.setup
  @schedule = Roqua::Scheduling::Schedule.new.tap do |new_schedule|
    yield(new_schedule)
    new_schedule.initialize_cronjob_table
  end
end

Public Instance Methods

add_task(name, options, &block) click to toggle source
# File lib/roqua/scheduling/schedule.rb, line 11
def add_task(name, options, &block)
  @tasks[name] = Roqua::Scheduling::Task.new(name, options, block)
end
initialize_cronjob_table() click to toggle source
# File lib/roqua/scheduling/schedule.rb, line 26
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