class Tina::RestorePlan

Constants

DAYS_PER_MONTH
MONTHLY_FREE_TIER_ALLOWANCE_FACTOR
PRICE_PER_GB_PER_HOUR

Public Class Methods

new(total_storage_size, objects, options = {}) click to toggle source
# File lib/tina/restore_plan.rb, line 8
def initialize(total_storage_size, objects, options = {})
  @total_storage_size = total_storage_size
  @objects = objects
  @price_per_gb_per_hour = options[:price_per_gb_per_hour] || PRICE_PER_GB_PER_HOUR

  @daily_allowance = @total_storage_size * MONTHLY_FREE_TIER_ALLOWANCE_FACTOR / DAYS_PER_MONTH
end

Public Instance Methods

price(total_time) click to toggle source
# File lib/tina/restore_plan.rb, line 16
def price(total_time)
  total_time = [total_time, 4 * 3600].max
  chunk_size = quadhourly_restore_rate(total_time)
  chunks = @objects.chunk(chunk_size)
  largest_chunk_object_size = chunks.map { |chunk| chunk.map(&:size).reduce(&:+) }.max
  quadhours = chunks.size
  quadhourly_allowance = @daily_allowance / ( [(24 / 4), quadhours].min * 4)

  peak_retrieval_rate = largest_chunk_object_size / 4
  peak_billable_retrieval_rate = [0, peak_retrieval_rate - quadhourly_allowance].max

  peak_billable_retrieval_rate * (@price_per_gb_per_hour / 1024 ** 3) * 720
end

Private Instance Methods

quadhourly_restore_rate(total_time) click to toggle source
# File lib/tina/restore_plan.rb, line 31
def quadhourly_restore_rate(total_time)
  @objects.total_size / (total_time / (4 * 3600))
end