Class: Sidetiq::Schedule
- Inherits:
-
Object
- Object
- Sidetiq::Schedule
- Defined in:
- lib/sidetiq/schedule.rb
Overview
Public: Recurrence schedule.
Instance Attribute Summary collapse
-
#backfill ⇒ Object
writeonly
Public: Writer for backfilling option.
-
#last_occurrence ⇒ Object
readonly
:nodoc:.
Class Method Summary collapse
-
.start_time ⇒ Object
Public: Start time offset from epoch used for calculating run times in the Sidetiq schedules.
Instance Method Summary collapse
-
#backfill? ⇒ Boolean
Public: Inquirer for backfilling option.
-
#initialize ⇒ Schedule
constructor
:nodoc:.
-
#method_missing(meth, *args, &block) ⇒ Object
:nodoc:.
-
#schedule_next?(time) ⇒ Boolean
Public: Checks if a job is due to be scheduled.
-
#set_options(hash) ⇒ Object
Internal: Set schedule options.
-
#to_s ⇒ Object
Public: Schedule to String.
Constructor Details
#initialize ⇒ Schedule
:nodoc:
16 17 18 |
# File 'lib/sidetiq/schedule.rb', line 16 def initialize # :nodoc: @schedule = IceCube::Schedule.new(self.class.start_time) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
:nodoc:
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/sidetiq/schedule.rb', line 20 def method_missing(meth, *args, &block) # :nodoc: if IceCube::Rule.respond_to?(meth) rule = IceCube::Rule.send(meth, *args, &block) @schedule.add_recurrence_rule(rule) rule elsif @schedule.respond_to?(meth) @schedule.send(meth, *args, &block) else super end end |
Instance Attribute Details
#backfill=(value) ⇒ Object (writeonly)
Public: Writer for backfilling option.
8 9 10 |
# File 'lib/sidetiq/schedule.rb', line 8 def backfill=(value) @backfill = value end |
#last_occurrence ⇒ Object (readonly)
:nodoc:
5 6 7 |
# File 'lib/sidetiq/schedule.rb', line 5 def last_occurrence @last_occurrence end |
Class Method Details
Instance Method Details
#backfill? ⇒ Boolean
Public: Inquirer for backfilling option.
67 68 69 |
# File 'lib/sidetiq/schedule.rb', line 67 def backfill? !!@backfill end |
#schedule_next?(time) ⇒ Boolean
Public: Checks if a job is due to be scheduled.
Returns true if a job is due, otherwise false.
35 36 37 38 39 40 41 42 |
# File 'lib/sidetiq/schedule.rb', line 35 def schedule_next?(time) next_occurrence = @schedule.next_occurrence(time) if @last_scheduled != next_occurrence.to_i @last_scheduled = next_occurrence.to_i return true end false end |
#set_options(hash) ⇒ Object
Internal: Set schedule options.
72 73 74 |
# File 'lib/sidetiq/schedule.rb', line 72 def (hash) self.backfill = hash[:backfill] if !hash[:backfill].nil? end |
#to_s ⇒ Object
Public: Schedule to String.
Examples
class MyWorker
include Sidekiq::Worker
include Sidetiq::Schedulable
recurrence { daily }
def perform
end
end
Sidetiq.schedules[MyWorker].to_s
# => "Daily"
Returns a String representing the schedule.
62 63 64 |
# File 'lib/sidetiq/schedule.rb', line 62 def to_s @schedule.to_s end |