Class: AwsCleaner

Inherits:
Object
  • Object
show all
Defined in:
lib/aws-cleaner.rb

Overview

main aws_cleaner lib

Defined Under Namespace

Modules: Chef, Notify, SQS, Sensu, Webhooks

Instance Method Summary collapse

Instance Method Details

#delete_message(id, config) ⇒ Object

delete the message from SQS



14
15
16
17
18
19
20
# File 'lib/aws-cleaner.rb', line 14

def delete_message(id, config)
  delete = AwsCleaner::SQS.client(config).delete_message(
    queue_url: config[:sqs][:queue],
    receipt_handle: id
  )
  delete ? true : false
end

#parse(body) ⇒ Object

return the body of the SQS message in JSON



102
103
104
105
106
# File 'lib/aws-cleaner.rb', line 102

def parse(body)
  JSON.parse(body)
rescue JSON::ParserError
  return false
end

#process_message(message_body) ⇒ Object

return the instance_id of the terminated instance



109
110
111
112
113
114
115
# File 'lib/aws-cleaner.rb', line 109

def process_message(message_body)
  return false if message_body['detail']['instance-id'].nil? &&
                  message_body['detail']['state'] != 'terminated'

  instance_id = message_body['detail']['instance-id']
  instance_id
end