Class: Roqua::Scheduling::Schedule
- Inherits:
-
Object
- Object
- Roqua::Scheduling::Schedule
- Defined in:
- lib/roqua/scheduling/schedule.rb
Constant Summary collapse
- BEGINNING_OF_EVERY_DAY =
proc { Time.now.beginning_of_day + 1.day }
- BEGINNING_OF_EVERY_HOUR =
proc { Time.now.beginning_of_hour + 1.hour }
Instance Attribute Summary collapse
-
#tasks ⇒ Object
readonly
Returns the value of attribute tasks.
Class Method Summary collapse
Instance Method Summary collapse
- #add_task(name, options, &block) ⇒ Object
-
#initialize ⇒ Schedule
constructor
A new instance of Schedule.
- #initialize_cronjob_table ⇒ Object
Constructor Details
#initialize ⇒ Schedule
Returns a new instance of Schedule.
7 8 9 |
# File 'lib/roqua/scheduling/schedule.rb', line 7 def initialize @tasks = {} end |
Instance Attribute Details
#tasks ⇒ Object (readonly)
Returns the value of attribute tasks.
2 3 4 |
# File 'lib/roqua/scheduling/schedule.rb', line 2 def tasks @tasks end |
Class Method Details
.current_schedule ⇒ Object
22 23 24 |
# File 'lib/roqua/scheduling/schedule.rb', line 22 def self.current_schedule @schedule ||= Roqua::Scheduling::Schedule.new end |
.setup ⇒ Object
15 16 17 18 19 20 |
# 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 |
Instance Method Details
#add_task(name, options, &block) ⇒ Object
11 12 13 |
# File 'lib/roqua/scheduling/schedule.rb', line 11 def add_task(name, , &block) @tasks[name] = Roqua::Scheduling::Task.new(name, , block) end |
#initialize_cronjob_table ⇒ Object
26 27 28 29 30 31 32 33 |
# 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 |