class Smith::Commands::Rm
Public Instance Methods
execute()
click to toggle source
# File lib/smith/commands/smithctl/rm.rb, line 4 def execute case target.size when 0 responder.succeed("No queue specified. Please specify a queue.") else worker = ->(queue_name, iter) do delete_queue(queue_name) do |delete_ok| delete_exchange(queue_name, &iter) end end # FIXME: Return errors to the caller rather than doing nothing or logging errors done = -> { responder.succeed } EM::Iterator.new(target).each(worker, done) end end
Private Instance Methods
delete_exchange(name, &blk)
click to toggle source
Delete an exchange.
@param name [String] name of the exchange. @yield calls the block when the exchange has been deleted @yieldparam [AMQ::Protocol::Channel::Close] the amqp close message FIXME: remove duplication
# File lib/smith/commands/smithctl/rm.rb, line 38 def delete_exchange(name, &blk) AMQP::Channel.new(Smith.connection) do |channel, ok| channel.on_error do |channel, channel_close| handler = (options[:ignore_errors]) ? blk : nil log_error(channel, channel_close, &handler) end channel.direct("#{Smith.config.smith.namespace}.#{name}", :passive => true) do |exchange| exchange_options = (options[:force]) ? {} : {:if_unused => true} exchange.delete(exchange_options) do |delete_ok| blk.call(delete_ok) end end end end
delete_queue(queue_name, &blk)
click to toggle source
Delete a queue.
@param queue_name [String] name of the queue. @yield calls the block when the queue has been deleted
@yieldparam [AMQ::Protocol::Channel::Close] the amqp close message FIXME: remove duplication
# File lib/smith/commands/smithctl/rm.rb, line 62 def delete_queue(queue_name, &blk) AMQP::Channel.new(Smith.connection) do |channel, ok| channel.on_error do |channel, channel_close| handler = (options[:ignore_errors]) ? blk : nil log_error(channel, channel_close, &handler) end channel.queue("#{Smith.config.smith.namespace}.#{queue_name}", :passive => true) do |queue| queue_options = (options[:force]) ? {} : {:if_unused => true, :if_empty => true} queue.delete(queue_options) do |delete_ok| blk.call(delete_ok) end end end end
extract_queue(message)
click to toggle source
# File lib/smith/commands/smithctl/rm.rb, line 93 def extract_queue(message) match = /.*?'(.*?)'.*$/.match(message) #[1] if match && match[1] match[1].sub(/smith\./, '') else message end end
log_error(channel, channel_close, &blk)
click to toggle source
Get's called when there is a channel error.
@param channel [AMQP::Channel] the channel that errored @param channel_close [AMQ::Protocol::Channel::Close] the amqp close message
which contains details of why the channel was claosed.
# File lib/smith/commands/smithctl/rm.rb, line 83 def log_error(channel, channel_close, &blk) base_error_msg = "#{channel_close.reply_code}, #{channel_close.reply_text}." if blk logger.error { "#{base_error_msg}. Ignoring as requested" } if options[:log_errors] blk.call else responder.succeed(base_error_msg) end end
options_spec()
click to toggle source
# File lib/smith/commands/smithctl/rm.rb, line 24 def options_spec banner "Remove the named queue. Multiple queues can be given", "<queue[s]>" opt :force, "force the removal even if there are messages on the queue", :short => :f opt :ignore_errors, "ignore any errors.", :default => false opt :log_errors, "print any errors messages.", :default => false end