Sha256: 9dced159df9f20d22d38b615eb0c1efe1838779bb3563b9cffa8eefa3965826c

Contents?: true

Size: 1.73 KB

Versions: 7

Compression:

Stored size: 1.73 KB

Contents

module Bunnish::Command
  module Delete
    def self.fetch_queue_name(queue_name_list, input_stream)
      return queue_name_list.shift if queue_name_list
      line = input_stream.gets
      return line.chomp if line
      return nil
    end
        
    def self.run(argv, input_stream=$stdin, output_stream=$stdout, error_stream=$stderr)
    
      params = Bunnish.parse_opts(argv)
      
      host = params[:host]
      port = params[:port]
      user = params[:user]
      password = params[:password]
      durable = params[:durable]
      
      log_label = params[:log_label]

      queue_name_list = argv.shift

      if queue_name_list.nil?
        Bunnish.logger.info("queue-name is not set")
        return 0
      end
      
      queue_name_list = queue_name_list.split(/[, \r\n]/)
      queue_name_list.delete('')
      
      bunny = Bunny.new(:logging => false, :spec => '09', :host=>host, :port=>port, :user=>user, :pass=>password)
      
      # start a communication session with the amqp server
      bunny.start
      
      exit_code = 0
      
      while queue_name = self.fetch_queue_name(queue_name_list, input_stream)
        # create/get queue
        # queue = bunny.queues[queue_name]
        queue = bunny.queue(queue_name, :durable=>durable)

        if queue.nil? then
          Bunnish.logger.info "#{log_label} #{queue_name} does not exist"
          next
        end

        result = queue.delete

        if result == :delete_ok then
          Bunnish.logger.info "#{log_label} deleted #{queue_name}"
        else
          Bunnish.logger.warn "#{log_label} failed to delete #{queue_name}"
          exit_code = 1
        end
      end
      
      # Close client
      bunny.stop
      
      return exit_code
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
bunnish-0.1.3 lib/bunnish/command/delete.rb
bunnish-0.1.2 lib/bunnish/command/delete.rb
bunnish-0.1.1 lib/bunnish/command/delete.rb
bunnish-0.1.0 lib/bunnish/command/delete.rb
bunnish-0.0.9 lib/bunnish/command/delete.rb
bunnish-0.0.8 lib/bunnish/command/delete.rb
bunnish-0.0.7 lib/bunnish/command/delete.rb