Sha256: 7158a2c81f7e81b73c049b7bb94e7bc4fe3de29acb9c85ee3be5cbddd96c3a3b

Contents?: true

Size: 954 Bytes

Versions: 4

Compression:

Stored size: 954 Bytes

Contents

# frozen_string_literal: true

module Puppet::Scheduler
  class SplayJob < Job
    attr_reader :splay

    def initialize(run_interval, splay_limit, &block)
      @splay = calculate_splay(splay_limit)
      super(run_interval, &block)
    end

    def interval_to_next_from(time)
      if last_run
        super
      else
        (start_time + splay) - time
      end
    end

    def ready?(time)
      if last_run
        super
      else
        start_time + splay <= time
      end
    end

    # Recalculates splay.
    #
    # @param splay_limit [Integer] the maximum time (in seconds) to delay before an agent's first run.
    # @return @splay [Integer] a random integer less than or equal to the splay limit that represents the seconds to
    # delay before next agent run.
    def splay_limit=(splay_limit)
      @splay = calculate_splay(splay_limit)
    end

    private

    def calculate_splay(limit)
      rand(limit + 1)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
puppet-8.7.0 lib/puppet/scheduler/splay_job.rb
puppet-8.7.0-x86-mingw32 lib/puppet/scheduler/splay_job.rb
puppet-8.7.0-x64-mingw32 lib/puppet/scheduler/splay_job.rb
puppet-8.7.0-universal-darwin lib/puppet/scheduler/splay_job.rb