diff --git a/lib/puppet/daemon.rb b/lib/puppet/daemon.rb index ce7fddbef1a..64802143ecb 100644 --- a/lib/puppet/daemon.rb +++ b/lib/puppet/daemon.rb @@ -165,6 +165,7 @@ def run_event_loop reparse_run = Puppet::Scheduler.create_job(Puppet[:filetimeout]) do Puppet.settings.reparse_config_files agent_run.run_interval = Puppet[:runinterval] + agent_run.splay_limit = Puppet[:splaylimit] if Puppet[:splay] if Puppet[:filetimeout] == 0 reparse_run.disable else diff --git a/lib/puppet/scheduler/splay_job.rb b/lib/puppet/scheduler/splay_job.rb index dd91165ddc5..9de9f77eb90 100644 --- a/lib/puppet/scheduler/splay_job.rb +++ b/lib/puppet/scheduler/splay_job.rb @@ -25,6 +25,15 @@ def ready?(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) diff --git a/spec/unit/daemon_spec.rb b/spec/unit/daemon_spec.rb index 93a5587f0b1..15e8db5f5df 100644 --- a/spec/unit/daemon_spec.rb +++ b/spec/unit/daemon_spec.rb @@ -79,6 +79,18 @@ def run_loop(jobs) daemon.start expect(scheduler.jobs[0]).not_to be_enabled end + + it "recalculates splay if splaylimit changes" do + # Set file timeout so the daemon reparses + Puppet[:filetimeout] = 1 + Puppet[:splay] = true + allow(agent).to receive(:run) + daemon.start + first_splay = scheduler.jobs[1].splay + allow(Kernel).to receive(:rand).and_return(1738) + scheduler.jobs[0].run(Time.now) + expect(scheduler.jobs[1].splay).to_not eq(first_splay) + end end describe "when stopping" do