Skip to content

Commit c85cfa3

Browse files
authored
Merge pull request #9381 from puppetlabs/backport-9345-to-7.x
[Backport 7.x] Update splaylimit during daemon run
2 parents 05ab44d + b6cf5c3 commit c85cfa3

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

lib/puppet/daemon.rb

+1
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ def run_event_loop
161161
reparse_run = Puppet::Scheduler.create_job(Puppet[:filetimeout]) do
162162
Puppet.settings.reparse_config_files
163163
agent_run.run_interval = Puppet[:runinterval]
164+
agent_run.splay_limit = Puppet[:splaylimit] if Puppet[:splay]
164165
if Puppet[:filetimeout] == 0
165166
reparse_run.disable
166167
else

lib/puppet/scheduler/splay_job.rb

+9
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ def ready?(time)
2323
end
2424
end
2525

26+
# Recalculates splay.
27+
#
28+
# @param splay_limit [Integer] the maximum time (in seconds) to delay before an agent's first run.
29+
# @return @splay [Integer] a random integer less than or equal to the splay limit that represents the seconds to
30+
# delay before next agent run.
31+
def splay_limit=(splay_limit)
32+
@splay = calculate_splay(splay_limit)
33+
end
34+
2635
private
2736

2837
def calculate_splay(limit)

spec/unit/daemon_spec.rb

+12
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,18 @@ def run_loop(jobs)
8686
daemon.start
8787
expect(scheduler.jobs[0]).not_to be_enabled
8888
end
89+
90+
it "recalculates splay if splaylimit changes" do
91+
# Set file timeout so the daemon reparses
92+
Puppet[:filetimeout] = 1
93+
Puppet[:splay] = true
94+
allow(agent).to receive(:run)
95+
daemon.start
96+
first_splay = scheduler.jobs[1].splay
97+
allow(Kernel).to receive(:rand).and_return(1738)
98+
scheduler.jobs[0].run(Time.now)
99+
expect(scheduler.jobs[1].splay).to_not eq(first_splay)
100+
end
89101
end
90102

91103
describe "when stopping" do

0 commit comments

Comments
 (0)