Class: Threasy::Schedule::Entry
- Inherits:
-
Object
- Object
- Threasy::Schedule::Entry
- Defined in:
- lib/threasy/schedule/entry.rb
Instance Attribute Summary collapse
-
#at ⇒ Object
Schedule Entry.
-
#job ⇒ Object
Schedule Entry.
-
#repeat ⇒ Object
Schedule Entry.
-
#schedule ⇒ Object
Schedule Entry.
-
#times ⇒ Object
Schedule Entry.
-
#work ⇒ Object
Schedule Entry.
Instance Method Summary collapse
- #due? ⇒ Boolean
- #future? ⇒ Boolean
-
#initialize(job, options = {}) ⇒ Entry
constructor
A new instance of Entry.
- #max_overdue ⇒ Object
- #once? ⇒ Boolean
- #overdue ⇒ Object
- #remove ⇒ Object
- #repeat? ⇒ Boolean
- #times_remaining? ⇒ Boolean
- #work! ⇒ Object
Constructor Details
#initialize(job, options = {}) ⇒ Entry
Returns a new instance of Entry.
16 17 18 19 20 21 22 23 24 |
# File 'lib/threasy/schedule/entry.rb', line 16 def initialize(job, = {}) self.schedule = .fetch(:schedule) { Threasy.schedules } self.work = .fetch(:work) { schedule.work } self.job = job self.repeat = [:every] seconds = .fetch(:in) { repeat || 60 } self.at = .fetch(:at) { Time.now + seconds } self.times = [:times] end |
Instance Attribute Details
#at ⇒ Object
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 |
#job ⇒ Object
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 |
#repeat ⇒ Object
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 |
#schedule ⇒ Object
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 |
#times ⇒ Object
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 times @times end |
#work ⇒ Object
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
34 35 36 |
# File 'lib/threasy/schedule/entry.rb', line 34 def due? Time.now > at end |
#future? ⇒ Boolean
38 39 40 |
# File 'lib/threasy/schedule/entry.rb', line 38 def future? ! due? end |
#max_overdue ⇒ Object
46 47 48 |
# File 'lib/threasy/schedule/entry.rb', line 46 def max_overdue Threasy.config.max_overdue end |
#once? ⇒ Boolean
30 31 32 |
# File 'lib/threasy/schedule/entry.rb', line 30 def once? ! repeat? end |
#overdue ⇒ Object
42 43 44 |
# File 'lib/threasy/schedule/entry.rb', line 42 def overdue Time.now - at end |
#remove ⇒ Object
65 66 67 |
# File 'lib/threasy/schedule/entry.rb', line 65 def remove schedule.remove_entry self end |
#repeat? ⇒ Boolean
26 27 28 |
# File 'lib/threasy/schedule/entry.rb', line 26 def repeat? !! repeat end |
#times_remaining? ⇒ Boolean
61 62 63 |
# File 'lib/threasy/schedule/entry.rb', line 61 def times_remaining? times.nil? || times > 0 end |
#work! ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/threasy/schedule/entry.rb', line 50 def work! return unless times_remaining? if once? || overdue < max_overdue work.enqueue job self.times -= 1 if times end self.at = at + repeat if repeat? end |