Skip to content

Commit

Permalink
move final reporting of results to rake task
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Gervasi committed Aug 10, 2015
1 parent 0cd45d9 commit 4a7d7c5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
25 changes: 12 additions & 13 deletions lib/broken_record/scanner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,23 @@
module BrokenRecord
class Scanner
def run(class_names)
classes = classes_to_validate(class_names)
ResultAggregator.new.tap do |aggregator|
classes = classes_to_validate(class_names)

BrokenRecord::Config.before_scan_callbacks.each { |callback| callback.call }
BrokenRecord::Config.before_scan_callbacks.each { |callback| callback.call }

jobs = BrokenRecord::Job.build_jobs(classes)
aggregator = ResultAggregator.new
jobs = BrokenRecord::Job.build_jobs(classes)

callback = proc do |_, _, result|
aggregator.add_result result if result.is_a? BrokenRecord::JobResult
end
callback = proc do |_, _, result|
aggregator.add_result result if result.is_a? BrokenRecord::JobResult
end

Parallel.each(jobs, :finish => callback) do |job|
ActiveRecord::Base.connection.reconnect!
BrokenRecord::Config.after_fork_callbacks.each { |callback| callback.call }
job.perform
Parallel.each(jobs, :finish => callback) do |job|
ActiveRecord::Base.connection.reconnect!
BrokenRecord::Config.after_fork_callbacks.each { |callback| callback.call }
job.perform
end
end

aggregator.report_final_results
end

private
Expand Down
3 changes: 2 additions & 1 deletion lib/broken_record/tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
scanner = BrokenRecord::Scanner.new
class_names = args[:class_name] ? [args[:class_name]] : []
class_names += args.extras
scanner.run(class_names)
aggregator = scanner.run(class_names)
aggregator.report_final_results
end
end

0 comments on commit 4a7d7c5

Please sign in to comment.