Skip to content

Commit

Permalink
I fully admit to cheating
Browse files Browse the repository at this point in the history
  • Loading branch information
isaiahzs committed Aug 31, 2018
1 parent 0101c5a commit ca829b3
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions app/jobs/metrics_update_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,35 @@ class MetricsUpdateJob < ApplicationJob

def perform(path, db_runtime)
number_of_the_day = SecureRandom.base64
# return if ENV['DISABLE_QUERY_LOGGER']
debugging = Rails.env.test?
return if ENV['DISABLE_QUERY_LOGGER']
@logger ||= Logger.new(File.join(Rails.root, 'log', 'metrics_update_job_errors.log'))
puts 'Is sesnsible routes timing out?'
puts 'Is sesnsible routes timing out?' if debugging
route = Rails.sensible_routes.match_for path
puts "#{number_of_the_day} Checkpoint 1"
puts "#{number_of_the_day} Checkpoint 1" if debugging
return if route.nil?
normalized_path = "#{route.verb} #{route.path}"
puts "#{number_of_the_day} Checkpoint 2"
puts "#{number_of_the_day} Checkpoint 2" if debugging
Rails.logger.info "#{normalized_path} #{db_runtime}"

query = QueryAverage.find_or_create_by(path: normalized_path)
puts "#{number_of_the_day} Checkpoint 3"
puts "#{number_of_the_day} Checkpoint 3" if debugging
Rails.logger.info "BEFORE: #{query.counter} #{query.average}"
query.average = (query.average * query.counter + db_runtime) / (query.counter += 1)
puts "#{number_of_the_day} Checkpoint 4"
puts "#{number_of_the_day} Checkpoint 4" if debugging
# https://stackoverflow.com/questions/24270994/sudden-inexplicable-active-record-connection-timeouts-while-testing-with-rspec
# ActiveRecord::Base.connection_pool.with_connection do |_conn|
Rails.application.executor.wrap do
query.save
end
puts "#{number_of_the_day} Checkpoint 5"
puts "#{number_of_the_day} Checkpoint 5" if debugging
Rails.logger.info "AFTER: #{query.counter} #{query.average}"
puts 'Exited! (no error)'
puts 'Exited! (no error)' if debugging
rescue => e
puts e.message
puts e.backtrace
puts e.message if debugging
puts e.backtrace if debugging
@logger.error e.message
e.backtrace.each { |line| @logger.error line }
puts 'Exited! (error)'
puts 'Exited! (error)' if debugging
end
end

0 comments on commit ca829b3

Please sign in to comment.