Skip to content

Commit

Permalink
Even more fun with logging\!
Browse files Browse the repository at this point in the history
  • Loading branch information
isaiahzs committed Aug 31, 2018
1 parent 226ceb7 commit b015a4f
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion app/jobs/metrics_update_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,26 @@ def perform(path, db_runtime)
@logger ||= Logger.new(File.join(Rails.root, 'log', 'metrics_update_job_errors.log'))
puts "Is sesnsible routes timing out?"
route = Rails.sensible_routes.match_for path
puts "Maybe!"
puts "Checkpoint 1"
return if route.nil?
normalized_path = "#{route.verb} #{route.path}"
puts "Checkpoint 2"
Rails.logger.info "#{normalized_path} #{db_runtime}"

query = QueryAverage.find_or_create_by(path: normalized_path)
puts "Checkpoint 3"
Rails.logger.info "BEFORE: #{query.counter} #{query.average}"
query.average = (query.average * query.counter + db_runtime) / (query.counter += 1)
puts "Checkpoint 4"
query.save
puts "Checkpoint 5"
Rails.logger.info "AFTER: #{query.counter} #{query.average}"
puts "Exited! (no error)"
rescue => e
puts e.message
puts e.backtrace
@logger.error e.message
e.backtrace.each { |line| @logger.error line }
puts "Exited! (error)"
end
end

0 comments on commit b015a4f

Please sign in to comment.