Class: DBcron::CrontabEntry
- Inherits:
-
Object
- Object
- DBcron::CrontabEntry
- Defined in:
- lib/dbcron.rb
Overview
nodoc
Instance Attribute Summary collapse
-
#last ⇒ Object
Returns the value of attribute last.
-
#name ⇒ Object
Returns the value of attribute name.
-
#task ⇒ Object
Returns the value of attribute task.
Instance Method Summary collapse
-
#initialize(name, cron:, task:) ⇒ CrontabEntry
constructor
A new instance of CrontabEntry.
- #ready?(time) ⇒ Boolean
- #run!(time) ⇒ Object
Constructor Details
#initialize(name, cron:, task:) ⇒ CrontabEntry
Returns a new instance of CrontabEntry.
56 57 58 59 60 61 |
# File 'lib/dbcron.rb', line 56 def initialize(name, cron:, task:) @name = name @cron = CronParser.new(cron, Celluloid::Actor[:clock].tz) @task = task @last = nil end |
Instance Attribute Details
#last ⇒ Object
Returns the value of attribute last.
54 55 56 |
# File 'lib/dbcron.rb', line 54 def last @last end |
#name ⇒ Object
Returns the value of attribute name.
54 55 56 |
# File 'lib/dbcron.rb', line 54 def name @name end |
#task ⇒ Object
Returns the value of attribute task.
54 55 56 |
# File 'lib/dbcron.rb', line 54 def task @task end |
Instance Method Details
#ready?(time) ⇒ Boolean
63 64 65 66 67 68 69 |
# File 'lib/dbcron.rb', line 63 def ready?(time) return false if @cron.next(time) > time + GRACE_TIME # is it time for the task? return false if @last && (time - @last) < interval # running too often? return false if !@last && time.sec > 2 * SLEEPY_TIME # for new tasks, start it as close as possible to the top of the minute true end |
#run!(time) ⇒ Object
71 72 73 74 75 |
# File 'lib/dbcron.rb', line 71 def run!(time) @last = time Celluloid::Actor[:task_runners].async.dispatch(@task) end |