Class: Sidetiq::Schedule

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeSchedule

: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_occurrenceObject (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.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


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 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

  tiq { 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