Class: AwsSqsMoniter::Aws::Builder::QueueBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/aws_sqs_moniter/aws/builder/queue_builder.rb

Instance Method Summary collapse

Constructor Details

#initialize(logger, name) ⇒ QueueBuilder

Returns a new instance of QueueBuilder.



5
6
7
8
9
10
# File 'lib/aws_sqs_moniter/aws/builder/queue_builder.rb', line 5

def initialize logger, name
  @logger = logger
  @name = name
  @arns = Arns.new
  @sqs = AwsSqsMoniter.sqs_client
end

Instance Method Details

#buildObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/aws_sqs_moniter/aws/builder/queue_builder.rb', line 12

def build
  @logger.info building_queue: @name

  queue_url = @sqs.create_queue(queue_name: @name)[:queue_url]

  queue_arn = @sqs.get_queue_attributes(
    queue_url: queue_url,
    attribute_names: ['QueueArn']).attributes['QueueArn']

  queue_configuration = AwsSqsMoniter.configuration.get_queue(@name)

  attributes = {
    'DelaySeconds' => queue_configuration.delay_seconds.to_s,
    'MessageRetentionPeriod' => queue_configuration.message_retention_period.to_s,
    'VisibilityTimeout' => queue_configuration.visibility_timeout.to_s
  }

  if AwsSqsMoniter.configuration.sqs_protocol == 'sqs'
    if queue_configuration.respond_to?(:redrive_policy)
      policy = '{}'
      policy = redrive_policy(
        queue_configuration.redrive_policy.dead_letter_queue,
        queue_configuration.redrive_policy.max_receive_count) if queue_configuration.redrive_policy.enabled

      attributes.merge! 'RedrivePolicy' => policy
    end

    policy = queue_policy
    attributes.merge! 'Policy' => policy
  end

  @sqs.set_queue_attributes queue_url: queue_url, attributes: attributes
end

#deleteObject



46
47
48
49
50
51
52
# File 'lib/aws_sqs_moniter/aws/builder/queue_builder.rb', line 46

def delete
  @logger.info deleting_queue: @name

  queue_url = @sqs.get_queue_url(queue_name: @name)[:queue_url]
  @sqs.delete_queue(queue_url: queue_url)
rescue ::Aws::SQS::Errors::NonExistentQueue
end