Class: EasyQ::Commands
- Inherits:
-
Object
- Object
- EasyQ::Commands
- Defined in:
- lib/easy_q/commands.rb
Defined Under Namespace
Classes: InvalidUsage
Constant Summary collapse
- USAGE =
"usage: easy_q command [args] [options]\n\nTo see list of available commands and options\n easy_q help\n"- HELP =
"usage: queues command [args] [options]\n\nReliable messaging queue manager, version \#{VERSION}\n\nAvailable commands:\n\n help\n Display this help message.\n\n start\n Start the easy_q as a standalone server\n\n stop\n Stop the easy_q server.\n\n empty <queue>\n Empty (delete all messages from) the named queue.\n\n install -c config.yml\n this creates the queue db schema\n\nAvailable options:\n\n -v --version\n Show version number.\n\n -c --config <path>\n Points to the queue manager configuration file.\n \n end\nend\n"
Instance Method Summary collapse
- #do_install ⇒ Object
-
#initialize ⇒ Commands
constructor
A new instance of Commands.
- #run ⇒ Object
Constructor Details
#initialize ⇒ Commands
Returns a new instance of Commands.
55 56 |
# File 'lib/easy_q/commands.rb', line 55 def initialize end |
Instance Method Details
#do_install ⇒ Object
133 134 135 136 137 138 139 140 141 |
# File 'lib/easy_q/commands.rb', line 133 def do_install @logger = Logger.new $stderr ActiveRecord::Base.logger = @logger ActiveRecord::Base.colorize_logging = false ActiveRecord::Base.establish_connection(@settings[:database]) ActiveRecord::Migrator.migrate("#{File.dirname(__FILE__)}/../../db/", nil) end |
#run ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/easy_q/commands.rb', line 58 def run #begin config_file = nil opts = OptionParser.new opts.on("-c FILE", "--config FILE", String) { |value| config_file = value } opts.on("-v", "--version") do puts "Reliable messaging queue manager, version #{VERSION}" exit end opts.on("-h", "--help") do puts HELP exit end args = opts.parse(ARGV) raise InvalidUsage if args.length < 1 if config_file.nil? puts "Specify a config file. -c settings.yml" exit end @settings = YAML::load_file(config_file) case args[0] when 'help' puts HELP when 'install' puts "installing..." do_install when 'start' service = Service.new(@settings) service.start begin while true exit if service.shut_down sleep 3 end rescue Interrupt puts exit end when 'stop' service = DRbObject.new(nil, "druby://localhost:#{@settings[:service][:port]}") service.stop when 'stats' service = DRbObject.new(nil, "druby://localhost:#{@settings[:service][:port]}") service.stats.each do |q,c| puts "#{q}: #{c}" end when 'peek' queue = args[1] number = args[2].to_i unless args[2].nil? direction = args[3] unless args[3].nil? service = DRbObject.new(nil, "druby://localhost:#{@settings[:service][:port]}") service.peek(queue,number,direction).each do |m| puts "####" puts "id: #{m[:id]}" puts "queue: #{m[:queue]}" puts "ttl: #{m[:ttl]}" puts "created_at #{m[:created_at]}" puts "body: #{m[:body]}" end when 'empty' queue = args[1] service = DRbObject.new(nil, "druby://localhost:#{@settings[:service][:port]}") service.empty(queue) end #rescue Exception => ex # puts ex #end end |