class SqsListQueues::Lister

Constants

ALPHABET

Allowed characters in SQS queue names, in that order (see above).

MAX_RESULTS

Ceiling of ListQueues results

Public Class Methods

new(sqs_client) click to toggle source
# File lib/sqs-list-queues/lister.rb, line 18
def initialize(sqs_client)
  @sqs_client = sqs_client
end

Public Instance Methods

get_full_list(prefix = "") click to toggle source
# File lib/sqs-list-queues/lister.rb, line 27
def get_full_list(prefix = "")
  urls = get_possibly_truncated_list prefix

  if urls.count < MAX_RESULTS
    return urls
  end

  last_result = urls.last
  last_name = File.basename last_result

  # If prefix = "foo"
  # and the last result we have is "foolish"
  # then to discover things later than this, we have to use a longer prefix
  # then "foo":
  # - "foom", "foon" (etc, for all possible character after "l"), each of
  # which must be iterated independently
  # - but for "fool"... we can try "fool" (which will certainly return some
  # results we already have), and _may_ return additional results

  problematic_letter = last_name[prefix.length]

  # The fool case
  fool_names = get_full_list(prefix + problematic_letter)
  index_of_last_result = fool_names.index last_result
  fool_names = fool_names[index_of_last_result+1 .. -1]

  # The foom, foon... case
  problematic_index = ALPHABET.index problematic_letter
  remaining_letters = ALPHABET[problematic_index+1 .. -1]

  remaining_names = remaining_letters.map do |letter|
    get_full_list(prefix + letter)
  end

  (urls + fool_names + remaining_names).flatten
end
get_possibly_truncated_list(prefix) click to toggle source
# File lib/sqs-list-queues/lister.rb, line 22
def get_possibly_truncated_list(prefix)
  # $stderr.puts "Querying with prefix = #{prefix.inspect}"
  @sqs_client.list_queues(queue_name_prefix: prefix).queue_urls
end