Class: Announce::Adapters::ShoryukenAdapter::Queue

Inherits:
BaseAdapter::Queue show all
Defined in:
lib/announce/adapters/shoryuken_adapter.rb

Instance Attribute Summary

Attributes inherited from BaseAdapter::Destination

#action, #options, #subject

Instance Method Summary collapse

Methods inherited from BaseAdapter::Queue

name_for

Methods inherited from BaseAdapter::Destination

app, delimiter, #initialize, #name, name_for, namespace, prefix, #publish

Constructor Details

This class inherits a constructor from Announce::Adapters::BaseAdapter::Destination

Instance Method Details

#arnObject



127
128
129
130
131
# File 'lib/announce/adapters/shoryuken_adapter.rb', line 127

def arn
   = Shoryuken::Client.
  region = sqs.config[:region]
  "arn:aws:sqs:#{region}:#{}:#{name}"
end

#createObject



118
119
120
121
122
123
124
125
# File 'lib/announce/adapters/shoryuken_adapter.rb', line 118

def create
  create_attributes = default_options.merge((options[:queues] || {}).stringify_keys)

  dlq_arn = create_dlq
  create_attributes['RedrivePolicy'] = %Q{{"maxReceiveCount":"10", "deadLetterTargetArn":"#{dlq_arn}"}"}

  sqs.create_queue(queue_name: name, attributes: create_attributes)[:queue_url]
end

#create_dlqObject



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/announce/adapters/shoryuken_adapter.rb', line 133

def create_dlq
  dlq_name = "#{name}_failures"

  dlq_options = {
    'MaximumMessageSize' => "#{(256 * 1024)}",
    'MessageRetentionPeriod' => "#{2 * 7 * 24 * 60 * 60}" # 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: ['QueueArn']
  )

  attrs.attributes['QueueArn']
end

#default_optionsObject



154
155
156
157
158
159
160
161
162
163
# File 'lib/announce/adapters/shoryuken_adapter.rb', line 154

def default_options
  {
    'DelaySeconds' => '0',
    'MaximumMessageSize' => "#{256 * 1024}",
    'VisibilityTimeout' => "#{60 * 60}", # 1 hour in seconds
    'ReceiveMessageWaitTimeSeconds' => '0',
    'MessageRetentionPeriod' => "#{7 * 24 * 60 * 60}", # 1 week in seconds
    'Policy' => policy
  }
end

#policyObject



165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/announce/adapters/shoryuken_adapter.rb', line 165

def policy
   = Shoryuken::Client.
  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}:#{}:*"
          }
        }
      }
    ]
  }.to_json
end

#sqsObject



190
191
192
# File 'lib/announce/adapters/shoryuken_adapter.rb', line 190

def sqs
  Shoryuken::Client.sqs
end