Skip to content

Instantly share code, notes, and snippets.

@denishaskin
Created May 7, 2014 01:26
Show Gist options
  • Save denishaskin/bd7ff6993c4bea728b73 to your computer and use it in GitHub Desktop.
Save denishaskin/bd7ff6993c4bea728b73 to your computer and use it in GitHub Desktop.
naive threading
def create_itineraries
threads = []
trip_parts.each do |trip_part|
threads << Thread.new do
begin
trip_part.create_itineraries
ensure
begin
if (ActiveRecord::Base.connection && ActiveRecord::Base.connection.active?)
ActiveRecord::Base.connection.close
end
rescue Exception => e
Rails.logger.error e
raise e
end
end
end
end
threads.each do |t|
t.join
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment