class Rufus::Scheduler::EveryJob

Recurring job with a certain frequency.

Attributes

frequency[R]

The frequency, in seconds, of this EveryJob

Public Class Methods

new(scheduler, t, params, &block) click to toggle source
# File lib/rufus/sc/jobs.rb, line 347
def initialize(scheduler, t, params, &block)

  super

  determine_frequency
  determine_at
end

Public Instance Methods

trigger() click to toggle source

Triggers the job (and reschedules it).

# File lib/rufus/sc/jobs.rb, line 357
def trigger

  schedule_next

  super
end

Protected Instance Methods

determine_at() click to toggle source
# File lib/rufus/sc/jobs.rb, line 375
def determine_at

  return unless @frequency

  @last = @at
    # the first time, @last will be nil

  now = Time.now.to_f

  @at = if @last
    @last + @frequency
  else
    if fi = @params[:first_in]
      now + Rufus.duration_to_f(fi)
    elsif fa = @params[:first_at]
      Rufus.at_to_f(fa)
    else
      now + @frequency
    end
  end

  while @at < now do
    @at += @frequency
  end if @params[:discard_past]
end
determine_frequency() click to toggle source
# File lib/rufus/sc/jobs.rb, line 366
def determine_frequency

  @frequency = if @t.is_a?(Fixnum) || @t.is_a?(Float)
    @t
  else
    Rufus.parse_duration_string(@t)
  end
end
schedule_next() click to toggle source

It’s an every job, have to schedule next time it occurs…

# File lib/rufus/sc/jobs.rb, line 403
def schedule_next

  determine_at

  @scheduler.send(:add_job, self)
end