Class: Tina::RestorePlan
- Inherits:
-
Object
- Object
- Tina::RestorePlan
- 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
-
#initialize(total_storage_size, objects, options = {}) ⇒ RestorePlan
constructor
A new instance of RestorePlan.
- #price(total_time) ⇒ Object
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, = {}) @total_storage_size = total_storage_size @objects = objects @price_per_gb_per_hour = [: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 |