Rufus::Scheduler::RepeatJob

Attributes

first_at[R]
last_at[RW]
paused_at[R]
times[RW]

Public Class Methods

new(scheduler, duration, opts, block) click to toggle source
# File lib/rufus/scheduler/jobs.rb, line 397
def initialize(scheduler, duration, opts, block)

  super

  @paused_at = nil

  @times = opts[:times]

  raise ArgumentError.new(
    "cannot accept :times => #{@times.inspect}, not nil or an int"
  ) unless @times == nil || @times.is_a?(Fixnum)

  self.first_at =
    opts[:first] || opts[:first_time] ||
    opts[:first_at] || opts[:first_in] ||
    0
  self.last_at =
    opts[:last] || opts[:last_at] || opts[:last_in]
end

Public Instance Methods

determine_id() click to toggle source
# File lib/rufus/scheduler/jobs.rb, line 472
def determine_id

  [
    self.class.name.split(':').last.downcase[0..-4],
    @scheduled_at.to_f,
    opts.hash.abs
  ].map(&:to_s).join('_')
end
first_at=(first) click to toggle source
# File lib/rufus/scheduler/jobs.rb, line 417
def first_at=(first)

  n = Time.now
  first = n + 0.001 if first == :now || first == :immediately

  @first_at = Rufus::Scheduler.parse_to_time(first)

  raise ArgumentError.new(
    "cannot set first[_at|_in] in the past: " +
    "#{first.inspect} -> #{@first_at.inspect}"
  ) if first != 0 && @first_at < n
end
last_at=(last) click to toggle source
# File lib/rufus/scheduler/jobs.rb, line 430
def last_at=(last)

  @last_at = last ? Rufus::Scheduler.parse_to_time(last) : nil

  raise ArgumentError.new(
    "cannot set last[_at|_in] in the past: " +
    "#{last.inspect} -> #{@last_at.inspect}"
  ) if last && @last_at < Time.now
end
occurrences(time0, time1) click to toggle source
# File lib/rufus/scheduler/jobs.rb, line 481
def occurrences(time0, time1)

  a = []

  nt = @next_time
  ts = @times

  loop do

    break if nt > time1
    break if ts && ts <= 0

    a << nt if nt >= time0

    nt = next_time_from(nt)
    ts = ts - 1 if ts
  end

  a
end
pause() click to toggle source
# File lib/rufus/scheduler/jobs.rb, line 457
def pause

  @paused_at = Time.now
end
paused?() click to toggle source
# File lib/rufus/scheduler/jobs.rb, line 467
def paused?

  @paused_at != nil
end
resume() click to toggle source
# File lib/rufus/scheduler/jobs.rb, line 462
def resume

  @paused_at = nil
end
trigger(time) click to toggle source
# File lib/rufus/scheduler/jobs.rb, line 440
def trigger(time)

  return if @paused_at
  return if time < @first_at
    #
    # TODO: remove me when @first_at gets reworked

  return (@next_time = nil) if @times && @times < 1
  return (@next_time = nil) if @last_at && time >= @last_at
    #
    # TODO: rework that, jobs are thus kept 1 step too much in @jobs

  super

  @times -= 1 if @times
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.