Skip to content

Instantly share code, notes, and snippets.

@mltsy
Created May 14, 2016 19:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mltsy/f485ea3b9694d8d0b516755ccfdd62c3 to your computer and use it in GitHub Desktop.
Save mltsy/f485ea3b9694d8d0b516755ccfdd62c3 to your computer and use it in GitHub Desktop.
Takes a filename of an event log (plain text, not gz), finds all the verification events in that file and reprocesses the hours.
desc "open a given log file, and extract/save hours from all Business Verification records logged"
task :reprocess_hours, [:filename] => :environment do |filename|
lines_read = lines_skipped = lines_failed = 0
puts "Reading lines from #{filename}..."
in_log = File.open(filename)
in_log.each do |line|
lines_read += 1
json = JSON.parse(line)
if json['event'] == 'verification_succeded'
uuid = json['business']['uuid']
hours = json['business']['hours']
lines_failed += 1 unless process_hours(uuid, hours)
else
lines_skipped += 1
end
puts "Completed: #{lines_read} (skipped: #{lines_skipped}, failed: #{lines_failed})" if lines_read % 100 == 0
end
end
def process_hours(uuid, hours)
# Jess types here! :) (raise an exception on failure)
return true
rescue e
puts "ERROR processing #{uuid} - #{e.class}: #{e.message}"
return false
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment