Class: Threasy::Schedule::Entry

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

Constant Summary collapse

MAX_OVERDUE =

5 minutes

300

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options = {})
  self.schedule = schedule
  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

Returns the value of attribute at.



96
97
98
# File 'lib/threasy/schedule.rb', line 96

def at
  @at
end

#jobObject

Returns the value of attribute job.



96
97
98
# File 'lib/threasy/schedule.rb', line 96

def job
  @job
end

#repeatObject

Returns the value of attribute repeat.



96
97
98
# File 'lib/threasy/schedule.rb', line 96

def repeat
  @repeat
end

#scheduleObject

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

Returns:

  • (Boolean)


114
115
116
# File 'lib/threasy/schedule.rb', line 114

def due?
  Time.now > at
end

#future?Boolean

Returns:

  • (Boolean)


118
119
120
# File 'lib/threasy/schedule.rb', line 118

def future?
  ! due?
end

#once?Boolean

Returns:

  • (Boolean)


110
111
112
# File 'lib/threasy/schedule.rb', line 110

def once?
  ! repeat?
end

#overdueObject



122
123
124
# File 'lib/threasy/schedule.rb', line 122

def overdue
  Time.now - at
end

#removeObject



133
134
135
# File 'lib/threasy/schedule.rb', line 133

def remove
  schedule.remove_entry self
end

#repeat?Boolean

Returns:

  • (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