class RdsRotateDbSnapshots

Attributes

options[R]

Public Class Methods

new(script_name: nil, cli: false, options: {}) click to toggle source
# File lib/rds_rotate_db_snapshots.rb, line 15
def initialize(script_name: nil, cli: false, options: {})
  @script_name = script_name
  @options = options
  @cli = cli
  parse_options if cli?
  @backoff_counter = 0
end

Public Instance Methods

client()
Alias for: rds_client
rds_client() click to toggle source
# File lib/rds_rotate_db_snapshots.rb, line 23
def rds_client
  @rds_client ||= RdsRotateDbSnapshots::RdsClient.new(@options)
end
Also aliased as: client
reset_backoff() click to toggle source
# File lib/rds_rotate_db_snapshots.rb, line 28
def reset_backoff
  @backoff_counter = 0
end
time_periods() click to toggle source
# File lib/rds_rotate_db_snapshots.rb, line 32
def time_periods
  @options[:time_periods]
end

Private Instance Methods

backoff() click to toggle source
# File lib/rds_rotate_db_snapshots.rb, line 46
def backoff
  @backoff_counter += 1

  # TODO: re-work
  if options && options[:backoff_limit].positive? && options[:backoff_limit] < @backoff_counter
    puts "Too many backoff attempts. Sorry it didn't work out."
    exit 2
  end

  naptime = rand(60) * @backoff_counter
  puts "Backing off for #{naptime} seconds..."
  sleep naptime
end
cli?() click to toggle source
# File lib/rds_rotate_db_snapshots.rb, line 38
def cli?
  !!@cli
end
parse_options() click to toggle source
# File lib/rds_rotate_db_snapshots.rb, line 42
def parse_options
  @options = RdsRotateDbSnapshots::OptionsParser.new(script_name: @script_name, cli: @cli).parse!
end