Skip to content

Instantly share code, notes, and snippets.

@mlyubarskyy
Created September 26, 2013 09:21
Show Gist options
  • Save mlyubarskyy/6711816 to your computer and use it in GitHub Desktop.
Save mlyubarskyy/6711816 to your computer and use it in GitHub Desktop.
diff --git a/app/services/car_importer.rb b/app/services/car_importer.rb
index d0a8d8f..f48319e 100644
--- a/app/services/car_importer.rb
+++ b/app/services/car_importer.rb
@@ -1,5 +1,6 @@
require 'open-uri'
require 'net/smtp'
+require 'benchmark'
module CarImporter
@@ -16,11 +17,13 @@ module CarImporter
include ActionView::Helpers::TextHelper # to get pluralize, etc
def run
+ Benchmark.bm do |x|
invalid_vehicles = []
import_started_at = Time.now
enabled_model_ids = []
- Schwacke::TYPE.all.batch(10).take(100).each do |type|
+ Schwacke::TYPE.all.batch(10).take(100).each_with_index do |type, i|
+ x.report("car:#{i}") do
name = type.TYPName
# we don't include the permalink here, because it may get overwritten
@@ -136,6 +139,7 @@ module CarImporter
logger.error "Exception: #{e.class}: #{e.message}\n\t#{model.permalink.inspect} #{model.errors.full_messages}"
invalid_vehicles << "[#{model.vehicle_id}] #{model.brand_name}/#{model.line_name}/#{model.body_name}: #{model.errors.full_messages}"
end
+ end
end
$statsd.gauge('car_importer.invalid_vehicles', invalid_vehicles.size)
@@ -143,6 +147,7 @@ module CarImporter
$statsd.gauge('car_importer.enabled_models', enabled_model_ids.length)
notify_about_new_models(new_models_attrs(import_started_at))
+ end
end
def retrieve_body_images_for_model(type, model)
diff --git a/lib/schwacke/lib/schwacke.rb b/lib/schwacke/lib/schwacke.rb
index bb1647c..f27de4d 100644
--- a/lib/schwacke/lib/schwacke.rb
+++ b/lib/schwacke/lib/schwacke.rb
@@ -2,7 +2,7 @@ require 'rubygems'
require 'data_mapper'
require 'db_fullfillment'
-DataMapper::Logger.new($stdout, :debug)
+DataMapper::Logger = nil#.new($stdout, :debug)
class DataMapper::Collection
def batch(n)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment