class Threasy::Schedule::Entry

Attributes

args[RW]

Schedule Entry

Represents a single entry in a schedule.

Class is responsible for keeping track of the timing and recurrance of a the supplied `job` object.

Entry instances are usually created by a `Threasy::Schedule` instance and should not be created by hand.

See `Threasy::Schedule#add`

at[RW]

Schedule Entry

Represents a single entry in a schedule.

Class is responsible for keeping track of the timing and recurrance of a the supplied `job` object.

Entry instances are usually created by a `Threasy::Schedule` instance and should not be created by hand.

See `Threasy::Schedule#add`

job[RW]

Schedule Entry

Represents a single entry in a schedule.

Class is responsible for keeping track of the timing and recurrance of a the supplied `job` object.

Entry instances are usually created by a `Threasy::Schedule` instance and should not be created by hand.

See `Threasy::Schedule#add`

repeat[RW]

Schedule Entry

Represents a single entry in a schedule.

Class is responsible for keeping track of the timing and recurrance of a the supplied `job` object.

Entry instances are usually created by a `Threasy::Schedule` instance and should not be created by hand.

See `Threasy::Schedule#add`

schedule[RW]

Schedule Entry

Represents a single entry in a schedule.

Class is responsible for keeping track of the timing and recurrance of a the supplied `job` object.

Entry instances are usually created by a `Threasy::Schedule` instance and should not be created by hand.

See `Threasy::Schedule#add`

times[RW]

Schedule Entry

Represents a single entry in a schedule.

Class is responsible for keeping track of the timing and recurrance of a the supplied `job` object.

Entry instances are usually created by a `Threasy::Schedule` instance and should not be created by hand.

See `Threasy::Schedule#add`

work[RW]

Schedule Entry

Represents a single entry in a schedule.

Class is responsible for keeping track of the timing and recurrance of a the supplied `job` object.

Entry instances are usually created by a `Threasy::Schedule` instance and should not be created by hand.

See `Threasy::Schedule#add`

Public Class Methods

new(job, options = {}) click to toggle source
# File lib/threasy/schedule/entry.rb, line 16
def initialize(job, options = {})
  self.schedule = options.fetch(:schedule) { Threasy.schedules }
  self.work     = options.fetch(:work) { schedule.work }
  self.job      = job
  self.repeat   = options[:every]
  seconds       = options.fetch(:in) { repeat || 60 }
  self.at       = options.fetch(:at) { Time.now + seconds }
  self.times    = options[:times]
  self.args     = options.fetch(:args) { [] }
end

Public Instance Methods

due?() click to toggle source
# File lib/threasy/schedule/entry.rb, line 35
def due?
  Time.now > at
end
future?() click to toggle source
# File lib/threasy/schedule/entry.rb, line 39
def future?
  ! due?
end
max_overdue() click to toggle source
# File lib/threasy/schedule/entry.rb, line 47
def max_overdue
  Threasy.config.max_overdue
end
once?() click to toggle source
# File lib/threasy/schedule/entry.rb, line 31
def once?
  ! repeat?
end
overdue() click to toggle source
# File lib/threasy/schedule/entry.rb, line 43
def overdue
  Time.now - at
end
remove() click to toggle source
# File lib/threasy/schedule/entry.rb, line 64
def remove
  schedule.remove_entry self
end
repeat?() click to toggle source
# File lib/threasy/schedule/entry.rb, line 27
def repeat?
  repeat && times_remaining?
end
times_remaining?() click to toggle source
# File lib/threasy/schedule/entry.rb, line 60
def times_remaining?
  times.nil? || times > 0
end
work!() click to toggle source
# File lib/threasy/schedule/entry.rb, line 51
def work!
  if once? || overdue < max_overdue
    work.enqueue(job, *args) if times_remaining?
    self.times -= 1 unless times.nil?
  end

  self.at = at + repeat if repeat?
end