Class: Smith::Commands::Dump
- Inherits:
-
Smith::CommandBase
- Object
- Smith::CommandBase
- Smith::Commands::Dump
- Defined in:
- lib/smith/commands/smithctl/dump.rb
Instance Attribute Summary
Attributes inherited from Smith::CommandBase
Instance Method Summary collapse
Methods inherited from Smith::CommandBase
#banner, #format_help, #initialize, #parse_options
Methods included from Logger
Constructor Details
This class inherits a constructor from Smith::CommandBase
Instance Method Details
#dump ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/smith/commands/smithctl/dump.rb', line 13 def dump case target.size when 0 "No queue specified. Please specify a queue." when 1 queue = target.first Messaging::Queue.(queue) do |queue_length| Messaging::Receiver.new(queue, :auto_ack => false, :prefetch => 1000, :passive => true) do |receiver| count = 0 t_start = Time.now.to_f receiver.on_error do |ch,channel_close| raise case channel_close.reply_code when 404 responder.succeed("Queue does not exist: #{queue}") else responder.succeed("Unknown error: #{channel_close.reply_text}") end Smith.stop end if queue_length > 0 EM.add_periodic_timer(1) do Messaging::Queue.(queue) do |queue_length| if queue_length == 0 t_end = Time.now.to_f if [:verbose] responder.succeed("dumped #{count} messages in #{t_end - t_start} seconds.") else responder.succeed("") end end end end receiver.subscribe do |payload, r| if payload EM.next_tick do STDOUT.puts MultiJson.dump(payload) end end count += 1 r.ack(true) end else responder.succeed("No messages on queue: #{queue}") end end end else "You can only specify one queue at a time" end end |
#execute ⇒ Object
8 9 10 11 |
# File 'lib/smith/commands/smithctl/dump.rb', line 8 def execute MultiJson.use(:oj) dump end |