class Dynamo::Record::TaskHelpers::Scale
Attributes
attribute_selector[R]
existing_throughput[R]
migration[R]
model[R]
model_name[R]
new_throughput[R]
Public Class Methods
new(model_name, attribute_selector, new_throughput)
click to toggle source
# File lib/dynamo/record/task_helpers/scale.rb, line 9 def initialize(model_name, attribute_selector, new_throughput) @model_name = model_name @attribute_selector = attribute_selector @new_throughput = new_throughput end
Public Instance Methods
run()
click to toggle source
# File lib/dynamo/record/task_helpers/scale.rb, line 15 def run return description if [model_name, attribute_selector, new_throughput].any?(&:nil?) @model = model_name.constantize @migration = Aws::Record::TableMigration.new(model) @existing_throughput = model.provisioned_throughput update_throughput success_message end
Private Instance Methods
both?()
click to toggle source
# File lib/dynamo/record/task_helpers/scale.rb, line 55 def both? attribute_selector.to_sym == :both end
description()
click to toggle source
# File lib/dynamo/record/task_helpers/scale.rb, line 73 def description <<~DESCRIPTION ---------------------------------------------------------------------- Here's some usage information: Scale a dynamo table. Requires three inputs. - ModelName ruby class of the model - attribute valid values include "both", "read" and "write" - new_throughput numerical value for the new read/write capacity units Example: `rake dynamo:scale[MySuperDynamoModel,both,50]` ---------------------------------------------------------------------- DESCRIPTION end
existing_read()
click to toggle source
# File lib/dynamo/record/task_helpers/scale.rb, line 51 def existing_read existing_throughput[:read_capacity_units] end
existing_write()
click to toggle source
# File lib/dynamo/record/task_helpers/scale.rb, line 47 def existing_write existing_throughput[:write_capacity_units] end
raise_attribute_error()
click to toggle source
# File lib/dynamo/record/task_helpers/scale.rb, line 67 def raise_attribute_error raise ArgumentError, <<~MESSAGE You didn't provide an appropriate attribute selection. We accept [:both, :read, :write] MESSAGE end
read?()
click to toggle source
# File lib/dynamo/record/task_helpers/scale.rb, line 59 def read? both? || attribute_selector.to_sym == :read end
success_message()
click to toggle source
# File lib/dynamo/record/task_helpers/scale.rb, line 28 def success_message "Successfully updated #{model.table_name} throughput to #{update_instructions[:provisioned_throughput]}" end
update_instructions()
click to toggle source
# File lib/dynamo/record/task_helpers/scale.rb, line 38 def update_instructions { provisioned_throughput: { write_capacity_units: (write? && new_throughput) || existing_write, read_capacity_units: (read? && new_throughput) || existing_read } } end
update_throughput()
click to toggle source
# File lib/dynamo/record/task_helpers/scale.rb, line 32 def update_throughput raise_attribute_error if !read? && !write? migration.update!(update_instructions) end
write?()
click to toggle source
# File lib/dynamo/record/task_helpers/scale.rb, line 63 def write? both? || attribute_selector.to_sym == :write end