Class: Announce::Adapters::ShoryukenAdapter::Queue
Instance Attribute Summary
#action, #options, #subject
Instance Method Summary
collapse
name_for
app, delimiter, #initialize, #name, name_for, namespace, prefix, #publish
Instance Method Details
#arn ⇒ Object
127
128
129
130
131
|
# File 'lib/announce/adapters/shoryuken_adapter.rb', line 127
def arn
account_id = Shoryuken::Client.account_id
region = sqs.config[:region]
"arn:aws:sqs:#{region}:#{account_id}:#{name}"
end
|
#create ⇒ Object
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_dlq ⇒ Object
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}" }
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_options ⇒ Object
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}", 'ReceiveMessageWaitTimeSeconds' => '0',
'MessageRetentionPeriod' => "#{7 * 24 * 60 * 60}", 'Policy' => policy
}
end
|
#policy ⇒ Object
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
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 ⇒ Object
190
191
192
|
# File 'lib/announce/adapters/shoryuken_adapter.rb', line 190
def sqs
Shoryuken::Client.sqs
end
|