Class: Threasy::Schedule::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/threasy/schedule/entry.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(job, options = {}) ⇒ Entry

Returns a new instance of Entry.



16
17
18
19
20
21
22
23
# 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 }
end

Instance Attribute Details

#atObject

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`



14
15
16
# File 'lib/threasy/schedule/entry.rb', line 14

def at
  @at
end

#jobObject

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`



14
15
16
# File 'lib/threasy/schedule/entry.rb', line 14

def job
  @job
end

#repeatObject

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`



14
15
16
# File 'lib/threasy/schedule/entry.rb', line 14

def repeat
  @repeat
end

#scheduleObject

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`



14
15
16
# File 'lib/threasy/schedule/entry.rb', line 14

def schedule
  @schedule
end

#workObject

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`



14
15
16
# File 'lib/threasy/schedule/entry.rb', line 14

def work
  @work
end

Instance Method Details

#due?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/threasy/schedule/entry.rb', line 33

def due?
  Time.now > at
end

#future?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/threasy/schedule/entry.rb', line 37

def future?
  ! due?
end

#max_overdueObject



45
46
47
# File 'lib/threasy/schedule/entry.rb', line 45

def max_overdue
  Threasy.config.max_overdue
end

#once?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/threasy/schedule/entry.rb', line 29

def once?
  ! repeat?
end

#overdueObject



41
42
43
# File 'lib/threasy/schedule/entry.rb', line 41

def overdue
  Time.now - at
end

#removeObject



56
57
58
# File 'lib/threasy/schedule/entry.rb', line 56

def remove
  schedule.remove_entry self
end

#repeat?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/threasy/schedule/entry.rb', line 25

def repeat?
  !! repeat
end

#work!Object



49
50
51
52
53
54
# File 'lib/threasy/schedule/entry.rb', line 49

def work!
  if once? || overdue < max_overdue
    work.enqueue job
  end
  self.at = at + repeat if repeat?
end