fix parsing of SQS bounce notifications

it _is_ double-json'd even with aws-sdk v2?

Change-Id: Ifb53b6d598fe5db4f724335144c08bf4654485a7
Reviewed-on: https://gerrit.instructure.com/100783
Product-Review: Cody Cutrer <cody@instructure.com>
QA-Review: Cody Cutrer <cody@instructure.com>
Reviewed-by: Jacob Fugal <jacob@instructure.com>
Tested-by: Jenkins
This commit is contained in:
Cody Cutrer 2017-01-28 18:38:37 -07:00
parent e4b5bcc2fe
commit a33b3648ab
2 changed files with 7 additions and 6 deletions

View File

@ -63,7 +63,8 @@ class BounceNotificationProcessor
end end
def parse_message(message) def parse_message(message)
sns_body = JSON.parse(message.body) sqs_body = JSON.parse(message.body)
sns_body = JSON.parse(sqs_body['Message'])
sns_body['bounce'] sns_body['bounce']
end end

View File

@ -21,17 +21,17 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
describe BounceNotificationProcessor do describe BounceNotificationProcessor do
before(:once) do before(:once) do
bounce_queue_log = File.read(File.dirname(__FILE__) + '/../fixtures/bounces.json') bounce_queue_log = File.read(File.dirname(__FILE__) + '/../fixtures/bounces.json')
@all_bounce_messages_json = JSON.parse(bounce_queue_log).map { |m| m['Message'] } @all_bounce_messages_json = JSON.parse(bounce_queue_log)
@soft_bounce_messages_json = @all_bounce_messages_json.select {|m| m.include?('Transient')} @soft_bounce_messages_json = @all_bounce_messages_json.select {|m| m['Message'].include?('Transient')}
@hard_bounce_messages_json = @all_bounce_messages_json.select {|m| m.include?('Permanent')} @hard_bounce_messages_json = @all_bounce_messages_json.select {|m| m['Message'].include?('Permanent')}
@bounce_count = @all_bounce_messages_json.count do |notification| @bounce_count = @all_bounce_messages_json.count do |notification|
JSON.parse(notification)['notificationType'] == 'Bounce' JSON.parse(notification['Message'])['notificationType'] == 'Bounce'
end end
end end
def mock_message(json) def mock_message(json)
message = mock message = mock
message.stubs(:body).returns(json) message.stubs(:body).returns(json.to_json)
message message
end end