Class: Puppet::Scheduler::Job
Direct Known Subclasses
Instance Attribute Summary collapse
-
#last_run ⇒ Object
Returns the value of attribute last_run.
-
#run_interval ⇒ Object
Returns the value of attribute run_interval.
-
#start_time ⇒ Object
Returns the value of attribute start_time.
Instance Method Summary collapse
- #disable ⇒ Object
- #enable ⇒ Object
- #enabled? ⇒ Boolean
-
#initialize(run_interval, &block) ⇒ Job
constructor
A new instance of Job.
- #interval_to_next_from(time) ⇒ Object
- #ready?(time) ⇒ Boolean
- #run(now) ⇒ Object
Constructor Details
#initialize(run_interval, &block) ⇒ Job
Returns a new instance of Job.
9 10 11 12 13 14 |
# File 'lib/puppet/scheduler/job.rb', line 9 def initialize(run_interval, &block) self.run_interval = run_interval @last_run = nil @run_proc = block @enabled = true end |
Instance Attribute Details
#last_run ⇒ Object
Returns the value of attribute last_run.
6 7 8 |
# File 'lib/puppet/scheduler/job.rb', line 6 def last_run @last_run end |
#run_interval ⇒ Object
Returns the value of attribute run_interval.
5 6 7 |
# File 'lib/puppet/scheduler/job.rb', line 5 def run_interval @run_interval end |
#start_time ⇒ Object
Returns the value of attribute start_time.
7 8 9 |
# File 'lib/puppet/scheduler/job.rb', line 7 def start_time @start_time end |
Instance Method Details
#disable ⇒ Object
36 37 38 |
# File 'lib/puppet/scheduler/job.rb', line 36 def disable @enabled = false end |
#enable ⇒ Object
32 33 34 |
# File 'lib/puppet/scheduler/job.rb', line 32 def enable @enabled = true end |
#enabled? ⇒ Boolean
28 29 30 |
# File 'lib/puppet/scheduler/job.rb', line 28 def enabled? @enabled end |
#interval_to_next_from(time) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/puppet/scheduler/job.rb', line 40 def interval_to_next_from(time) if ready?(time) 0 else @run_interval - (time - @last_run) end end |
#ready?(time) ⇒ Boolean
20 21 22 23 24 25 26 |
# File 'lib/puppet/scheduler/job.rb', line 20 def ready?(time) if @last_run @last_run + @run_interval <= time else true end end |
#run(now) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/puppet/scheduler/job.rb', line 48 def run(now) @last_run = now if @run_proc @run_proc.call(self) end end |