Skip to content

Instantly share code, notes, and snippets.

@piotr-galas
Created November 15, 2017 14:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save piotr-galas/f209c0ebb84a644d8ac2af7a82a9e670 to your computer and use it in GitHub Desktop.
Save piotr-galas/f209c0ebb84a644d8ac2af7a82a9e670 to your computer and use it in GitHub Desktop.
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