appoxy / aws

Amazon Web Services (AWS) Ruby Gem

Home Page:https://rubygems.org/gems/aws

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Aws::Sqs.queue ignores 'create' parameter

phiggins opened this issue · comments

The documentation for the Aws::Sqs.create method indicates that its second parameter controls whether a new SQS queue is created if one by that name doesn't exist.

Looking at the code, it seems that there is some commented out code that does as the docs indicate, but the currently active code ignores the second parameter. This commit looks like the one responsible for the change, citing "performance enhancement".

Either the documentation should be changed to indicate that a queue is created if it does not exist, or that commit should be reverted.

Looking back at that, it looks like the issue was that queue_url_by_name calls list_queues to see if queue exists, then calls create_queue meaning two one or two calls if create=true. The current way only does one call. The queue should be created no matter what in the new code so yes, create_queue is ignored, but it'll act as if it were true. Are you having issues with it?

Actually, I guess maybe you don't necessarily want to create the queue?

Err, yes, you got it in your second reply. I'm sorry I wasn't more clear in my initial report.

For my current use case, I don't want to create any queues; if I have a queue name that does not exist I want to raise an error rather than create a new queue. From reading the docs I thought I could call Aws::Sqs.create("my_queue", false) and have it return nil (or something) if the queue did not exist already.

Wouldn't something like this work for all four cases?

def queue(queue_name, create=true, visibility=nil)
  url = if create
    @interface.create_queue(queue_name, visibility) # this returns the url even if it exists
  else      
    @interface.queue_url_by_name(queue_name)
  end

  url ? Queue.new(self, url) : nil
end

ya, good call. Will change.