Class: Puppet::Provider::RabbitmqCli
- Inherits:
-
Puppet::Provider
- Object
- Puppet::Provider
- Puppet::Provider::RabbitmqCli
- Defined in:
- lib/puppet/provider/rabbitmq_cli.rb
Class Method Summary collapse
- .home_tmp_command(name, path) ⇒ Object
- .rabbitmq_running ⇒ Object
- .rabbitmq_version ⇒ Object
- .rabbitmqctl_list(resource, *opts) ⇒ Object
-
.run_with_retries(count = 30, step = 6, timeout = 10, &block) ⇒ Object
Retry the given code block ‘count’ retries or until the command succeeds.
Class Method Details
.home_tmp_command(name, path) ⇒ Object
28 29 30 31 32 |
# File 'lib/puppet/provider/rabbitmq_cli.rb', line 28 def self.home_tmp_command(name, path) has_command name, path do environment HOME: '/tmp', LC_ALL: 'en_US.UTF-8' end end |
.rabbitmq_running ⇒ Object
59 60 61 62 63 64 |
# File 'lib/puppet/provider/rabbitmq_cli.rb', line 59 def self.rabbitmq_running rabbitmqctl('-q', 'status') true rescue Puppet::ExecutionFailure, Timeout::Error false end |
.rabbitmq_version ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/puppet/provider/rabbitmq_cli.rb', line 39 def self.rabbitmq_version return @rabbitmq_version if defined? @rabbitmq_version output = rabbitmqctl('-q', 'status') version = output.match(%r{RabbitMQ.*?([\d.]+)}) @rabbitmq_version = version[1] if version @rabbitmq_version end |
.rabbitmqctl_list(resource, *opts) ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/puppet/provider/rabbitmq_cli.rb', line 48 def self.rabbitmqctl_list(resource, *opts) version = rabbitmq_version list_opts = if version && Puppet::Util::Package.versioncmp(version, '3.7.9') >= 0 ['-q', '--no-table-headers'] else ['-q'] end rabbitmqctl("list_#{resource}", *list_opts, *opts) end |
.run_with_retries(count = 30, step = 6, timeout = 10, &block) ⇒ Object
Retry the given code block ‘count’ retries or until the command succeeds. Use ‘step’ delay between retries. Limit each query time by ‘timeout’. For example:
users = self.class.run_with_retries { rabbitmqctl 'list_users' }
71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/puppet/provider/rabbitmq_cli.rb', line 71 def self.run_with_retries(count = 30, step = 6, timeout = 10, &block) count.times do |_n| output = Timeout.timeout(timeout, &block) rescue Puppet::ExecutionFailure, Timeout::Error Puppet.debug 'Command failed, retrying' sleep step else Puppet.debug 'Command succeeded' return output end raise Puppet::Error, "Command is still failing after #{count * step} seconds expired!" end |