class Announce::Adapters::ShoryukenAdapter::Queue

Constants

DLQ_SUFFIX

Public Instance Methods

arn() click to toggle source
# File lib/announce/adapters/shoryuken_adapter.rb, line 160
def arn
  account_id = Shoryuken::Client.account_id
  region = sqs.config[:region]
  "arn:aws:sqs:#{region}:#{account_id}:#{name}"
end
create() click to toggle source
# File lib/announce/adapters/shoryuken_adapter.rb, line 141
def create
  dlq_arn = create_dlq

  create_attributes =
    default_options.merge((options[:queues] || {}).stringify_keys)
  create_attributes["RedrivePolicy"] =
    '{"maxReceiveCount":"10", "deadLetterTargetArn":"' + dlq_arn + '"}'

  sqs.create_queue(queue_name: name, attributes: create_attributes)[
    :queue_url
  ]
end
create_dlq() click to toggle source
# File lib/announce/adapters/shoryuken_adapter.rb, line 166
def create_dlq
  dlq_options = {
    "MaximumMessageSize" => (256 * 1024).to_s,
    "MessageRetentionPeriod" => (2 * 7 * 24 * 60 * 60).to_s
    # 2 weeks in seconds
  }

  dlq = sqs.create_queue(queue_name: dlq_name, attributes: dlq_options)

  attrs =
    sqs.get_queue_attributes(
      queue_url: dlq[:queue_url], attribute_names: %w[QueueArn]
    )

  attrs.attributes["QueueArn"]
end
default_options() click to toggle source
# File lib/announce/adapters/shoryuken_adapter.rb, line 191
def default_options
  {
    "DelaySeconds" => "0",
    "MaximumMessageSize" => (256 * 1024).to_s,
    "VisibilityTimeout" => (60 * 60).to_s,
    # 1 hour in seconds
    "ReceiveMessageWaitTimeSeconds" => "0",
    "MessageRetentionPeriod" => (7 * 24 * 60 * 60).to_s,
    # 1 week in seconds
    "Policy" => policy
  }
end
dlq_arn() click to toggle source
# File lib/announce/adapters/shoryuken_adapter.rb, line 183
def dlq_arn
  [arn, DLQ_SUFFIX].join(self.class.delimiter)
end
dlq_name() click to toggle source
# File lib/announce/adapters/shoryuken_adapter.rb, line 187
def dlq_name
  [name, DLQ_SUFFIX].join(self.class.delimiter)
end
policy() click to toggle source
# File lib/announce/adapters/shoryuken_adapter.rb, line 204
def policy
  account_id = Shoryuken::Client.account_id
  region = sqs.config[:region]
  {
    "Version" => "2012-10-17",
    "Id" => "AnnounceSNStoSQS",
    "Statement" => [
      {
        "Sid" => "1",
        "Effect" => "Allow",
        "Principal" => { "AWS" => "*" },
        "Action" => "sqs:*",
        "Resource" => arn,
        "Condition" => {
          "ArnLike" => {
            "aws:SourceArn" => "arn:aws:sns:#{region}:#{account_id}:*"
          }
        }
      }
    ]
  }.to_json
end
sqs() click to toggle source
# File lib/announce/adapters/shoryuken_adapter.rb, line 227
def sqs
  Shoryuken::Client.sqs
end
verify() click to toggle source
# File lib/announce/adapters/shoryuken_adapter.rb, line 154
def verify
  Announce.logger.warn(
    "Verify SQS Queue: #{arn}\n\t with DLQ: #{dlq_arn}"
  )
end