Class: Tina::RestorePlan

Inherits:
Object
  • Object
show all
Defined in:
lib/tina/restore_plan.rb

Defined Under Namespace

Classes: ObjectCollection

Constant Summary collapse

MONTHLY_FREE_TIER_ALLOWANCE_FACTOR =
0.05
DAYS_PER_MONTH =
30
PRICE_PER_GB_PER_HOUR =
0.011

Instance Method Summary collapse

Constructor Details

#initialize(total_storage_size, objects, options = {}) ⇒ RestorePlan

Returns a new instance of RestorePlan.



8
9
10
11
12
13
14
# 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

Instance Method Details

#price(total_time) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
# 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