summaryrefslogtreecommitdiffstats
path: root/lib/puppet/agent
diff options
context:
space:
mode:
Diffstat (limited to 'lib/puppet/agent')
-rw-r--r--lib/puppet/agent/downloader.rb24
-rw-r--r--lib/puppet/agent/splayer.rb29
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