Module: MovableInk::AWS::SNS

Included in:
MovableInk::AWS
Defined in:
lib/movable_ink/aws/sns.rb

Instance Method Summary collapse

Instance Method Details

#notify_and_sleep(seconds, error_class) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/movable_ink/aws/sns.rb', line 19

def notify_and_sleep(seconds, error_class)
  message = "Throttled by AWS. Sleeping #{seconds} seconds, (#{error_class})"
  notify_slack(subject: 'API Throttled',
               message: message)
  puts message
  sleep seconds
end

#notify_nsq_can_not_be_drainedObject



27
28
29
30
# File 'lib/movable_ink/aws/sns.rb', line 27

def notify_nsq_can_not_be_drained
  notify_slack(subject: 'NSQ not drained',
               message: 'Unable to drain NSQ')
end

#notify_slack(subject:, message:) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/movable_ink/aws/sns.rb', line 32

def notify_slack(subject:, message:)
  run_with_backoff do
    sns.publish(topic_arn: sns_slack_topic_arn,
                subject: "#{subject} (#{instance_id}, #{my_region})",
                message: message)
  end
end

#sns(region: my_region) ⇒ Object



4
5
6
7
# File 'lib/movable_ink/aws/sns.rb', line 4

def sns(region: my_region)
  @sns_client ||= {}
  @sns_client[region] ||= Aws::SNS::Client.new(region: region)
end

#sns_slack_topic_arnObject



9
10
11
12
13
14
15
16
17
# File 'lib/movable_ink/aws/sns.rb', line 9

def sns_slack_topic_arn
  run_with_backoff do
    sns.list_topics.each do |resp|
      resp.topics.each do |topic|
        return topic.topic_arn if topic.topic_arn.include? "slack-aws-alerts"
      end
    end
  end
end