Class: QueueFetcher

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

Overview

Encapsulates the design decision about how to namespace SQS queues with environment-specific prefixes, as well as the dependency on the existence of a queueing interface. Typically this class only gets used at initialization time, a la this example from a Rails production.rb config file:

config.after_initialize do

interface = RightAws::SqsGen2.new(aws_access_key_id,aws_secret_access_key)
qf = QueueFetcher.new(interface,"production")
DatawarehouseLoader.queue = qf.fetch("datawarehouse_loader")

end

In tests, the queue interface could be set to a mock object

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(queue_interface, queue_prefix) ⇒ QueueFetcher

Returns a new instance of QueueFetcher.



18
19
20
21
# File 'lib/queue_fetcher.rb', line 18

def initialize(queue_interface,queue_prefix)
  @queue_interface = queue_interface
  @queue_prefix = queue_prefix
end

Instance Attribute Details

#queue_interfaceObject

Returns the value of attribute queue_interface.



15
16
17
# File 'lib/queue_fetcher.rb', line 15

def queue_interface
  @queue_interface
end

#queue_prefixObject

Returns the value of attribute queue_prefix.



16
17
18
# File 'lib/queue_fetcher.rb', line 16

def queue_prefix
  @queue_prefix
end

Instance Method Details

#fetch(queue_name) ⇒ Object



23
24
25
# File 'lib/queue_fetcher.rb', line 23

def fetch(queue_name)
  queue_interface.queue("#{queue_prefix}_#{queue_name}")
end