Skip to content

Commit

Permalink
logic improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
timalces committed Jan 11, 2021
1 parent dc9facb commit d062b18
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions models/azure_project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -413,22 +413,17 @@ def get_compute_costs(cost_entries, date, rerun)
cost_breakdown[group] += value
end
end

if rerun && compute_cost_log
cost_breakdown.each do |key, value|
scope = key == :total ? "compute" : key
log = self.cost_logs.find_by(date: date.to_s, scope: scope)
if log
log.assign_attributes(cost: cost_breakdown[key], timestamp: Time.now.to_s)
log.save!
end
end
else
cost_breakdown.each do |key, value|
scope = key == :total ? "compute" : key

cost_breakdown.each do |key, value|
scope = key == :total ? "compute" : key
log = self.cost_logs.find_by(date: date.to_s, scope: scope)
if log && rerun
log.assign_attributes(cost: cost_breakdown[key], timestamp: Time.now.to_s)
log.save!
elsif !log
log = CostLog.create(
project_id: id,
cost: cost_breakdown[key],
cost: value,
currency: 'GBP',
scope: scope,
date: date.to_s,
Expand Down

0 comments on commit d062b18

Please sign in to comment.