Class: EventQ::Amazon::QueueManager

Inherits:
Object
  • Object
show all
Defined in:
lib/eventq_aws/aws_queue_manager.rb

Constant Summary collapse

VISIBILITY_TIMEOUT =
'VisibilityTimeout'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ QueueManager

Returns a new instance of QueueManager.



7
8
9
10
11
12
13
14
# File 'lib/eventq_aws/aws_queue_manager.rb', line 7

def initialize(options)

  if options[:client] == nil
    raise ':client (QueueClient) must be specified.'.freeze
  end

  @client = options[:client]
end

Instance Method Details

#create_queue(queue) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/eventq_aws/aws_queue_manager.rb', line 26

def create_queue(queue)
  response = @client.sqs.create_queue({
                                          queue_name: queue.name,
                                          attributes: {
                                              VISIBILITY_TIMEOUT => 300.to_s #5 minutes
                                          }
                                      })

  return response.queue_url
end

#drop_queue(queue) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/eventq_aws/aws_queue_manager.rb', line 37

def drop_queue(queue)

  q = get_queue(queue)

  @client.sqs.delete_queue({ queue_url: q})

  return true

end

#drop_topic(event_type) ⇒ Object



47
48
49
50
51
52
# File 'lib/eventq_aws/aws_queue_manager.rb', line 47

def drop_topic(event_type)
  topic_arn = @client.get_topic_arn(event_type)
  @client.sns.delete_topic({ topic_arn: topic_arn})

  return true
end

#get_queue(queue) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/eventq_aws/aws_queue_manager.rb', line 16

def get_queue(queue)

  if queue_exists?(queue)
    update_queue(queue)
  else
    create_queue(queue)
  end

end

#queue_exists?(queue) ⇒ Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/eventq_aws/aws_queue_manager.rb', line 54

def queue_exists?(queue)
  return @client.sqs.list_queues({ queue_name_prefix: queue.name }).queue_urls.length > 0
end

#update_queue(queue) ⇒ Object



58
59
60
61
62
63
64
65
66
67
# File 'lib/eventq_aws/aws_queue_manager.rb', line 58

def update_queue(queue)
  url = @client.get_queue_url(queue)
  @client.sqs.set_queue_attributes({
                                       queue_url: url, # required
                                        attributes: {
                                            VISIBILITY_TIMEOUT => 300.to_s # 5 minutes
                                        }
                                    })
  return url
end