Created
November 15, 2017 14:31
-
-
Save piotr-galas/f209c0ebb84a644d8ac2af7a82a9e670 to your computer and use it in GitHub Desktop.
This file contains 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
THREADS_NUM.times.map { | |
Thread.new do | |
while !@objects.empty? | |
object = @objects.pop | |
@mutex.synchronize do | |
print "#{Time.now.strftime("%H:%M")} - Saving data: #{@objects.length} items left. " | |
print "\r" | |
end | |
if object.save | |
@mutex.synchronize { @successful_imports += 1 } | |
else | |
error_data = { | |
:invent => object.try(:equipment).try(:invent), | |
:errors => object.errors.full_messages.map(&:to_s).join(', ') | |
} | |
@bad_imports << error_data | |
end | |
end | |
end | |
}.each {|thread| thread.join } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment