1+ # frozen_string_literal: true
2+
13class Puppet ::Provider ::RabbitmqCli < Puppet ::Provider
24 initvars
35
@@ -38,7 +40,7 @@ def self.rabbitmq_version
3840 return @rabbitmq_version if defined? @rabbitmq_version
3941
4042 output = rabbitmqctl ( '-q' , 'status' )
41- version = output . match ( %r{RabbitMQ.*?([\d \ . ]+)} )
43+ version = output . match ( %r{RabbitMQ.*?([\d .]+)} )
4244 @rabbitmq_version = version [ 1 ] if version
4345 @rabbitmq_version
4446 end
@@ -56,35 +58,32 @@ def self.rabbitmqctl_list(resource, *opts)
5658
5759 def self . rabbitmq_running
5860 rabbitmqctl ( '-q' , 'status' )
59- return true
61+ true
6062 rescue Puppet ::ExecutionFailure , Timeout ::Error
61- return false
63+ false
6264 end
6365
6466 # Retry the given code block 'count' retries or until the
6567 # command succeeds. Use 'step' delay between retries.
6668 # Limit each query time by 'timeout'.
6769 # For example:
6870 # users = self.class.run_with_retries { rabbitmqctl 'list_users' }
69- def self . run_with_retries ( count = 30 , step = 6 , timeout = 10 )
71+ def self . run_with_retries ( count = 30 , step = 6 , timeout = 10 , & block )
7072 count . times do |_n |
71- begin
72- output = Timeout . timeout ( timeout ) do
73- yield
74- end
75- rescue Puppet ::ExecutionFailure , Timeout ::Error
76- Puppet . debug 'Command failed, retrying'
77- sleep step
78- else
79- Puppet . debug 'Command succeeded'
80- return output
81- end
73+ output = Timeout . timeout ( timeout , &block )
74+ rescue Puppet ::ExecutionFailure , Timeout ::Error
75+ Puppet . debug 'Command failed, retrying'
76+ sleep step
77+ else
78+ Puppet . debug 'Command succeeded'
79+ return output
8280 end
8381 raise Puppet ::Error , "Command is still failing after #{ count * step } seconds expired!"
8482 end
8583
8684 def self . define_instance_method ( name )
8785 return if method_defined? ( name )
86+
8887 define_method ( name ) do |*args , &block |
8988 self . class . send ( name , *args , &block )
9089 end
0 commit comments