lib/deputy.rb in deputy-0.1.42 vs lib/deputy.rb in deputy-0.1.43
- old
+ new
@@ -98,10 +98,12 @@
end
end
end
def self.run_plugins
+ sleep_random_interval
+
content = get("/plugins.rb")
Scout.plugins(content).each do |interval, plugin|
run_every_n_minutes = interval/60
minutes_to_wait = run_every_n_minutes - (START_MINUTE % run_every_n_minutes)
@@ -143,9 +145,23 @@
home = File.expand_path('~')
["#{home}/.deputy.yml", '/etc/deputy.yml'].each do |file|
return YAML.load(File.read(file)) if File.exist?(file)
end
raise "No deputy.yml found in /etc or #{home}"
+ end
+
+ def self.sleep_random_interval
+ if max = config['max_random_start_delay']
+ constant_number = Socket.gethostname.sum{|x| x[0]}
+ sleep seeded_random(max, constant_number)
+ end
+ end
+
+ def self.seeded_random(max_rand, seed)
+ old = srand(seed)
+ result = rand(max_rand)
+ srand(old)
+ result
end
# stolen from klarlack -- http://github.com/schoefmax/klarlack
# to get an reliable timeout that wont fail on other platforms
# or if sytem_timer is missing
\ No newline at end of file