Class: Sidetiq::Schedule

Inherits:
Object
  • Object
show all
Defined in:
lib/sidetiq/schedule.rb

Overview

Public: Recurrence schedule.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSchedule

: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_occurrenceObject (readonly)

:nodoc:


5
6
7
# File 'lib/sidetiq/schedule.rb', line 5

def last_occurrence
  @last_occurrence
end

Class Method Details

.start_timeObject

Public: Start time offset from epoch used for calculating run times in the Sidetiq schedules.


12
13
14
# File 'lib/sidetiq/schedule.rb', line 12

def self.start_time
  Sidetiq.config.utc ? Time.utc(2010, 1, 1) : Time.local(2010, 1, 1)
end

Instance Method Details

#backfill?Boolean

Public: Inquirer for backfilling option.

Returns:

  • (Boolean)

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.

Returns:

  • (Boolean)

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 set_options(hash)
  self.backfill = hash[:backfill] if !hash[:backfill].nil?
end

#to_sObject

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