File: job.rb

package info (click to toggle)
puppet-agent 7.23.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 19,092 kB
  • sloc: ruby: 245,074; sh: 456; makefile: 38; xml: 33
file content (53 lines) | stat: -rw-r--r-- 880 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
module Puppet::Scheduler
  class Job
    attr_reader :run_interval
    attr_accessor :last_run
    attr_accessor :start_time

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

    def run_interval=(interval)
      @run_interval = [interval, 0].max
    end

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

    def enabled?
      @enabled
    end

    def enable
      @enabled = true
    end

    def disable
      @enabled = false
    end

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

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