Class: Threasy::Schedule::Entry
- Inherits:
-
Object
- Object
- Threasy::Schedule::Entry
- Defined in:
- lib/threasy/schedule.rb
Constant Summary collapse
- MAX_OVERDUE =
5 minutes
300
Instance Attribute Summary collapse
-
#at ⇒ Object
Returns the value of attribute at.
-
#job ⇒ Object
Returns the value of attribute job.
-
#repeat ⇒ Object
Returns the value of attribute repeat.
-
#schedule ⇒ Object
Returns the value of attribute schedule.
Instance Method Summary collapse
- #due? ⇒ Boolean
- #future? ⇒ Boolean
-
#initialize(schedule, job, options = {}) ⇒ Entry
constructor
A new instance of Entry.
- #once? ⇒ Boolean
- #overdue ⇒ Object
- #remove ⇒ Object
- #repeat? ⇒ Boolean
- #work! ⇒ Object
Constructor Details
#initialize(schedule, job, options = {}) ⇒ Entry
Returns a new instance of Entry.
98 99 100 101 102 103 104 |
# File 'lib/threasy/schedule.rb', line 98 def initialize(schedule, job, = {}) self.schedule = schedule self.job = job self.repeat = [:every] seconds = .fetch(:in){ repeat || 60 } self.at = .fetch(:at){ Time.now + seconds } end |
Instance Attribute Details
#at ⇒ Object
Returns the value of attribute at.
96 97 98 |
# File 'lib/threasy/schedule.rb', line 96 def at @at end |
#job ⇒ Object
Returns the value of attribute job.
96 97 98 |
# File 'lib/threasy/schedule.rb', line 96 def job @job end |
#repeat ⇒ Object
Returns the value of attribute repeat.
96 97 98 |
# File 'lib/threasy/schedule.rb', line 96 def repeat @repeat end |
#schedule ⇒ Object
Returns the value of attribute schedule.
96 97 98 |
# File 'lib/threasy/schedule.rb', line 96 def schedule @schedule end |
Instance Method Details
#due? ⇒ Boolean
114 115 116 |
# File 'lib/threasy/schedule.rb', line 114 def due? Time.now > at end |
#future? ⇒ Boolean
118 119 120 |
# File 'lib/threasy/schedule.rb', line 118 def future? ! due? end |
#once? ⇒ Boolean
110 111 112 |
# File 'lib/threasy/schedule.rb', line 110 def once? ! repeat? end |
#overdue ⇒ Object
122 123 124 |
# File 'lib/threasy/schedule.rb', line 122 def overdue Time.now - at end |
#remove ⇒ Object
133 134 135 |
# File 'lib/threasy/schedule.rb', line 133 def remove schedule.remove_entry self end |
#repeat? ⇒ Boolean
106 107 108 |
# File 'lib/threasy/schedule.rb', line 106 def repeat? !! repeat end |
#work! ⇒ Object
126 127 128 129 130 131 |
# File 'lib/threasy/schedule.rb', line 126 def work! if once? || overdue < MAX_OVERDUE schedule.work.enqueue job end self.at = at + repeat if repeat? end |