Class: DBcron::CrontabEntry

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

Overview

nodoc

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#lastObject

Returns the value of attribute last.



54
55
56
# File 'lib/dbcron.rb', line 54

def last
  @last
end

#nameObject

Returns the value of attribute name.



54
55
56
# File 'lib/dbcron.rb', line 54

def name
  @name
end

#taskObject

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

Returns:

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