Class: Sidetiq::Schedule
- Inherits:
-
Object
- Object
- Sidetiq::Schedule
- Defined in:
- lib/sidetiq/schedule.rb
Overview
Public: Recurrence schedule.
Constant Summary collapse
- START_TIME =
Public: Start time offset from epoch used for calculating run times in the Sidetiq schedules.
Sidetiq.config.utc ? Time.utc(2010, 1, 1) : Time.local(2010, 1, 1)
Instance Attribute Summary collapse
-
#backfill ⇒ Object
writeonly
Public: Writer for backfilling option.
-
#last_occurrence ⇒ Object
readonly
:nodoc:.
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:
14 15 16 |
# File 'lib/sidetiq/schedule.rb', line 14 def initialize # :nodoc: @schedule = IceCube::Schedule.new(START_TIME) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
:nodoc:
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/sidetiq/schedule.rb', line 18 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 |
Instance Method Details
#backfill? ⇒ Boolean
Public: Inquirer for backfilling option.
65 66 67 |
# File 'lib/sidetiq/schedule.rb', line 65 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.
33 34 35 36 37 38 39 40 |
# File 'lib/sidetiq/schedule.rb', line 33 def schedule_next?(time) next_occurrence = @schedule.next_occurrence(time) if @last_scheduled != next_occurrence @last_scheduled = next_occurrence return true end false end |
#set_options(hash) ⇒ Object
Internal: Set schedule options.
70 71 72 |
# File 'lib/sidetiq/schedule.rb', line 70 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.
60 61 62 |
# File 'lib/sidetiq/schedule.rb', line 60 def to_s @schedule.to_s end |