Skip to content

Commit

Permalink
(PUP-12061) Log when periodic agent runs
Browse files Browse the repository at this point in the history
Provide more context when the agent runs so it's clearer whether splay is
enabled and what the limits are. We don't want to do this for the reparse and
signal jobs, because they run every 15 and 5 seconds, respectively.

The info message is of the form:

    Running agent every 20 seconds with splay 5 of 10 seconds

This message is logged whenever the agent is running periodically, not for
onetime runs. Whether we're daemonized doesn't affect the behavior. This is
because we always call Puppet::Daemon#start when running periodically to
run the event loop.
  • Loading branch information
joshcooper committed Sep 26, 2024
1 parent 9b1d464 commit ccfcec2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
8 changes: 7 additions & 1 deletion lib/puppet/daemon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,13 @@ def remove_pidfile

# Loop forever running events - or, at least, until we exit.
def run_event_loop
agent_run = Puppet::Scheduler.create_job(Puppet[:runinterval], Puppet[:splay], Puppet[:splaylimit]) do
agent_run = Puppet::Scheduler.create_job(Puppet[:runinterval], Puppet[:splay], Puppet[:splaylimit]) do |job|
if job.splay != 0
Puppet.info "Running agent every #{job.run_interval} seconds with splay #{job.splay} of #{job.splay_limit} seconds"
else
Puppet.info "Running agent every #{job.run_interval} seconds"
end

# Splay for the daemon is handled in the scheduler
agent.run(:splay => false)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/scheduler/splay_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

def initialize(run_interval, splay_limit, &block)
@splay, @splay_limit = calculate_splay(splay_limit)
Expand Down
4 changes: 4 additions & 0 deletions spec/unit/scheduler/splay_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,8 @@
job.splay_limit = splay_limit + 1
expect(job.splay).to eq(new_splay)
end

it "returns the splay_limit" do
expect(job.splay_limit).to eq(splay_limit)
end
end

0 comments on commit ccfcec2

Please sign in to comment.