Skip to content

Commit

Permalink
Merge pull request #29 from stbenjam/9408
Browse files Browse the repository at this point in the history
fixes #9408 - handle case when durations are strings
  • Loading branch information
stbenjam committed Feb 20, 2015
2 parents 5bcd5e7 + 2541e91 commit 3a49494
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
16 changes: 8 additions & 8 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# This configuration was generated by `rubocop --auto-gen-config`
# on 2015-02-08 16:56:10 +0100 using RuboCop version 0.28.0.
# on 2015-02-20 17:14:35 +0100 using RuboCop version 0.28.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 15
# Offense count: 16
Metrics/AbcSize:
Max: 35
Max: 38

# Offense count: 2
# Configuration parameters: CountComments.
Expand All @@ -16,21 +16,21 @@ Metrics/ClassLength:

# Offense count: 2
Metrics/CyclomaticComplexity:
Max: 10
Max: 11

# Offense count: 200
# Configuration parameters: AllowURI, URISchemes.
Metrics/LineLength:
Max: 201

# Offense count: 8
# Offense count: 9
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 30
Max: 34

# Offense count: 3
Metrics/PerceivedComplexity:
Max: 13
Max: 15

# Offense count: 10
# Cop supports --auto-correct.
Expand Down Expand Up @@ -98,7 +98,7 @@ Style/GuardClause:
Style/RaiseArgs:
EnforcedStyle: compact

# Offense count: 1
# Offense count: 3
Style/RescueModifier:
Enabled: false

Expand Down
6 changes: 5 additions & 1 deletion app/services/foreman_salt/report_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,11 @@ def calculate_metrics
end
end

time[resource] = result['duration'] if result['duration']
time[resource] = if result['duration'].is_a? String
Float(result['duration'].delete(' ms')) rescue nil
else
result['duration']
end
end

time[:total] = time.values.inject(&:+)
Expand Down
22 changes: 22 additions & 0 deletions db/migrate/20150220122707_fix_incorrect_report_metrics.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class FixIncorrectReportMetrics < ActiveRecord::Migration
def up
Report.all.each do |report|
next unless report.metrics && report.metrics['time']
metrics = report.metrics.dup

report.metrics['time'].each do |resource, time|
metrics['time'][resource] = if time.is_a? String
Float(time.delete(' ms')) rescue nil
else
time
end
end

report.update_attributes(:metrics => metrics) if metrics != report.metrics
end
end

def down
# Nothing
end
end

0 comments on commit 3a49494

Please sign in to comment.