Skip to content

Commit

Permalink
Charge SCVMM's vm only until it is retired.
Browse files Browse the repository at this point in the history
  • Loading branch information
isimluk committed Jan 11, 2017
1 parent 75fb55a commit 41e9832
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions app/models/chargeback/consumption.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ def consumed_hours_in_interval
# Why we need this?
# 1) We cannot charge for hours until the resources existed (vm provisioned in the middle of month)
# 2) We cannot charge for future hours (i.e. weekly report on Monday, should charge just monday)
# 3) We cannot charge for hours after the resource has been retired.
@consumed_hours_in_interval ||= begin
consuption_start = [@start_time, resource.try(:created_on)].compact.max
consumption_end = [Time.current, @end_time].min
(consumption_end - consuption_start).round / 1.hour
consumption_end = [Time.current, @end_time, resource.try(:retires_on)].compact.min
consumed = (consumption_end - consuption_start).round / 1.hour
consumed > 0 ? consumed : 0
end
end

Expand Down

0 comments on commit 41e9832

Please sign in to comment.