diff --git a/lib/movable_ink/aws.rb b/lib/movable_ink/aws.rb index e6c1cab..ff8e66c 100644 --- a/lib/movable_ink/aws.rb +++ b/lib/movable_ink/aws.rb @@ -64,15 +64,22 @@ def sns_slack_topic_arn end def notify_and_sleep(seconds) - message = "Instance Id #{instance_id} has been throttled in #{region}." - sns.publish(:topic_arn => sns_slack_topic_arn, :message => message, :subject => "API Throttled") - puts "Throttled by AWS. Sleeping #{seconds} seconds." + message = "Throttled by AWS. Sleeping #{seconds} seconds" + notify_slack(subject: 'API Throttled', + message: message) + puts message sleep seconds end def notify_nsq_can_not_be_drained - message = "Unable to drain nsq on instance #{instance_id}" - sns.publish(:topic_arn => sns_slack_topic_arn, :message => message, :subject => "Nsq not drained") + notify_slack(subject: 'NSQ not drained', + message: 'Unable to drain NSQ') + end + + def notify_slack(subject:, message:) + sns.publish(topic_arn: sns_slack_topic_arn, + subject: "#{subject} (#{instance_id}, #{region})" + message: message) end def mi_env @@ -125,15 +132,16 @@ def all_instances def load_all_instances run_with_backoff do - resp = ec2.describe_instances(filters: [{ - name: 'instance-state-name', - values: ['running'] - }, - { - name: 'tag:mi:env', - values: [mi_env] - } - ]) + resp = ec2.describe_instances(filters: [ + { + name: 'instance-state-name', + values: ['running'] + }, + { + name: 'tag:mi:env', + values: [mi_env] + } + ]) reservations = resp.reservations while (!resp.last_page?) do resp = resp.next_page diff --git a/lib/movable_ink/version.rb b/lib/movable_ink/version.rb index 936b714..cb67aef 100644 --- a/lib/movable_ink/version.rb +++ b/lib/movable_ink/version.rb @@ -1,5 +1,5 @@ module MovableInk module AWS - VERSION = '0.0.3' + VERSION = '0.0.4' end end