diff options
| author | Luke Kanies <luke@madstop.com> | 2009-01-19 16:29:17 -0600 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2009-02-06 18:08:39 -0600 |
| commit | 8f5cbc349daa868020b009851ee97ea3f29fcfbf (patch) | |
| tree | 5cfc7826cb90d7daf8aa1014b83ee1877255ebee /lib/puppet/agent | |
| parent | 25b28c58c22bae718794dc679f10c61665af0b15 (diff) | |
| download | puppet-8f5cbc349daa868020b009851ee97ea3f29fcfbf.tar.gz puppet-8f5cbc349daa868020b009851ee97ea3f29fcfbf.tar.xz puppet-8f5cbc349daa868020b009851ee97ea3f29fcfbf.zip | |
This is work that I've decided not to keep
so I'm just applying it here so it continues to show
up in the history in case I ever want to look at it again.
Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'lib/puppet/agent')
| -rw-r--r-- | lib/puppet/agent/downloader.rb | 24 | ||||
| -rw-r--r-- | lib/puppet/agent/splayer.rb | 29 |
2 files changed, 33 insertions, 20 deletions
diff --git a/lib/puppet/agent/downloader.rb b/lib/puppet/agent/downloader.rb index 46a64d52d..e838d4d79 100644 --- a/lib/puppet/agent/downloader.rb +++ b/lib/puppet/agent/downloader.rb @@ -1,36 +1,20 @@ require 'puppet/agent' +# A simple class that abstracts downloading files +# fromthe server. class Puppet::Agent::Downloader attr_reader :name, :path, :source, :ignore - # Determine the timeout value to use. - def self.timeout - timeout = Puppet[:configtimeout] - case timeout - when String: - if timeout =~ /^\d+$/ - timeout = Integer(timeout) - else - raise ArgumentError, "Configuration timeout must be an integer" - end - when Integer: # nothing - else - raise ArgumentError, "Configuration timeout must be an integer" - end - - return timeout - end - # Evaluate our download, returning the list of changed values. def evaluate Puppet.info "Retrieving #{name}" files = [] begin - Timeout.timeout(self.class.timeout) do + Timeout.timeout(Puppet::Agent.timeout) do catalog.apply do |trans| trans.changed?.find_all do |resource| - yield resource if block_given? + yield resource[:path] if block_given? files << resource[:path] end end diff --git a/lib/puppet/agent/splayer.rb b/lib/puppet/agent/splayer.rb new file mode 100644 index 000000000..6c2b1ba51 --- /dev/null +++ b/lib/puppet/agent/splayer.rb @@ -0,0 +1,29 @@ +require 'puppet/agent' + +# The class that handles sleeping for the appropriate splay +# time, if at all. +class Puppet::Agent::Splayer + attr_reader :splayed + + # Should we splay? + def splay? + Puppet[:splay] + end + + # Sleep for a random but consistent period of time if configured to + # do so. + def splay + return unless Puppet[:splay] + return if splayed? + + time = rand(Integer(Puppet[:splaylimit]) + 1) + Puppet.info "Sleeping for %s seconds (splay is enabled)" % time + sleep(time) + @splayed = true + end + + # Have we already splayed? + def splayed? + defined?(@splayed) and @splayed + end +end |
