Skip to content

Commit

Permalink
Make ls more similar to $ watch
Browse files Browse the repository at this point in the history
  • Loading branch information
Pablo Cantero committed Jul 30, 2017
1 parent 5df2099 commit 079bb26
Showing 1 changed file with 2 additions and 25 deletions.
27 changes: 2 additions & 25 deletions bin/cli/sqs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,29 +49,6 @@ def batch_send(url, messages)
end

def find_all(url, limit, &block)
count = 0
batch_size = limit > 10 ? 10 : limit

loop do
n = limit - count
batch_size = n if n < batch_size

messages = sqs.receive_message(
queue_url: url,
max_number_of_messages: batch_size,
message_attribute_names: ['All']
).messages

messages.each { |m| yield m }

count += messages.size

break if count >= limit
break if messages.empty?
end

count
end

def list_and_print_queues(urls)
attrs = %w(QueueArn ApproximateNumberOfMessages ApproximateNumberOfMessagesNotVisible LastModifiedTimestamp)
Expand All @@ -96,8 +73,8 @@ def dump_file(path, queue_name)
end

desc 'ls [QUEUE-NAME-PREFIX]', 'Lists queues'
method_option :watch, aliases: '-w', type: :boolean, desc: 'watch queues'
method_option :watch_interval, type: :numeric, default: 10, desc: 'watch interval'
method_option :watch, aliases: '-w', type: :boolean, desc: 'watch queues'
method_option :interval, aliases: '-n', type: :numeric, default: 2, desc: 'watch interval'
def ls(queue_name_prefix = '')
trap('SIGINT', 'EXIT') # expect ctrl-c from loop

Expand Down

0 comments on commit 079bb26

Please sign in to comment.