]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/rabbitmq/lib/puppet/provider/rabbitmqctl.rb
move to puppetlabs rabbitmq module
[dsa-puppet.git] / 3rdparty / modules / rabbitmq / lib / puppet / provider / rabbitmqctl.rb
1 class Puppet::Provider::Rabbitmqctl < Puppet::Provider
2   initvars
3   commands :rabbitmqctl => 'rabbitmqctl'
4
5   def self.rabbitmq_version
6     output = rabbitmqctl('-q', 'status')
7     version = output.match(/\{rabbit,"RabbitMQ","([\d\.]+)"\}/)
8     version[1] if version
9   end
10
11   # Retry the given code block 'count' retries or until the
12   # command suceeeds. Use 'step' delay between retries.
13   # Limit each query time by 'timeout'.
14   # For example:
15   #   users = self.class.run_with_retries { rabbitmqctl 'list_users' }
16   def self.run_with_retries(count=30, step=6, timeout=10)
17     count.times do |n|
18       begin
19         output = Timeout::timeout(timeout) do
20           yield
21         end
22       rescue Puppet::ExecutionFailure, Timeout
23         Puppet.debug 'Command failed, retrying'
24         sleep step
25       else
26         Puppet.debug 'Command succeeded'
27         return output
28       end
29     end
30     raise Puppet::Error, "Command is still failing after #{count * step} seconds expired!"
31   end
32
33 end