Module: Sidetiq::Schedulable::ClassMethods

Includes:
Sidetiq::SubclassTracking
Defined in:
lib/sidetiq/schedulable.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Sidetiq::SubclassTracking

#inherited, #subclasses

Instance Attribute Details

#scheduleObject

Public: Returns the Sidetiq::Schedule for this worker.


27
28
29
# File 'lib/sidetiq/schedulable.rb', line 27

def schedule
  @schedule ||= Sidetiq::Schedule.new
end

Instance Method Details

#last_scheduled_occurrenceObject

Public: Returns a Float timestamp of the last scheduled run.


22
23
24
# File 'lib/sidetiq/schedulable.rb', line 22

def last_scheduled_occurrence
  get_timestamp "last"
end

#next_scheduled_occurrenceObject

Public: Returns a Float timestamp of the next scheduled run.


32
33
34
# File 'lib/sidetiq/schedulable.rb', line 32

def next_scheduled_occurrence
  get_timestamp "next"
end

#recurrence(options = {}, &block) ⇒ Object

:nodoc:


40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/sidetiq/schedulable.rb', line 40

def recurrence(options = {}, &block) # :nodoc:
  schedule.instance_eval(&block)
  schedule.set_options(options)

  # deleting schedulable keys if schedule changed since last reccurence definition
  if Sidekiq.server?
    old_description = get_schedulable_key("schedule_description")
    if old_description != schedule.to_s
      get_schedulable_keys.map do |key|
        Sidekiq.redis_pool.with { |r| r.del(key) }
      end
      set_schedulable_key("schedule_description", schedule.to_s)
    end
  end
end

#schedule_descriptionObject


36
37
38
# File 'lib/sidetiq/schedulable.rb', line 36

def schedule_description
  get_schedulable_key("schedule_description")
end