Class: Puppet::Scheduler::Job

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet/scheduler/job.rb

Direct Known Subclasses

SplayJob

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(run_interval, &block) ⇒ Job


7
8
9
10
11
12
# File 'lib/puppet/scheduler/job.rb', line 7

def initialize(run_interval, &block)
  self.run_interval = run_interval
  @last_run = nil
  @run_proc = block
  @enabled = true
end

Instance Attribute Details

#last_runObject

Returns the value of attribute last_run


4
5
6
# File 'lib/puppet/scheduler/job.rb', line 4

def last_run
  @last_run
end

#run_intervalObject

Returns the value of attribute run_interval


3
4
5
# File 'lib/puppet/scheduler/job.rb', line 3

def run_interval
  @run_interval
end

#start_timeObject

Returns the value of attribute start_time


5
6
7
# File 'lib/puppet/scheduler/job.rb', line 5

def start_time
  @start_time
end

Instance Method Details

#disableObject


34
35
36
# File 'lib/puppet/scheduler/job.rb', line 34

def disable
  @enabled = false
end

#enableObject


30
31
32
# File 'lib/puppet/scheduler/job.rb', line 30

def enable
  @enabled = true
end

#enabled?Boolean


26
27
28
# File 'lib/puppet/scheduler/job.rb', line 26

def enabled?
  @enabled
end

#interval_to_next_from(time) ⇒ Object


38
39
40
41
42
43
44
# File 'lib/puppet/scheduler/job.rb', line 38

def interval_to_next_from(time)
  if ready?(time)
    0
  else
    @run_interval - (time - @last_run)
  end
end

#ready?(time) ⇒ Boolean


18
19
20
21
22
23
24
# File 'lib/puppet/scheduler/job.rb', line 18

def ready?(time)
  if @last_run
    @last_run + @run_interval <= time
  else
    true
  end
end

#run(now) ⇒ Object


46
47
48
49
50
51
# File 'lib/puppet/scheduler/job.rb', line 46

def run(now)
  @last_run = now
  if @run_proc
    @run_proc.call(self)
  end
end