-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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