Send an Airbrake notification whenever an import fails

1.0
Fernando Espinosa 13 years ago
parent 379da3b4c8
commit fa679c9c45

@ -5,7 +5,7 @@ class Table < Sequel::Model(:user_tables)
# Privacy constants
PRIVATE = 0
PUBLIC = 1
# Ignore mass-asigment on not allowed columns
self.strict_param_setting = false
@ -92,7 +92,7 @@ class Table < Sequel::Model(:user_tables)
aux_cartodb_id_column = "cartodb_id_aux_#{Time.now.to_i}"
user_database.run("ALTER TABLE #{self.name} RENAME COLUMN cartodb_id TO #{aux_cartodb_id_column}")
end
# When tables are created using ogr2ogr they are added a ogc_fid primary key
# In that case:
# - If cartodb_id already exists, remove ogc_fid
@ -152,6 +152,15 @@ class Table < Sequel::Model(:user_tables)
$tables_metadata.del key
owner.in_database(:as => :superuser).run("DROP TABLE IF EXISTS #{self.name}")
end
Airbrake.notify(
:error_class => "Import Error",
:error_message => "Import Error: #{e.message}",
:parameters => {
:database => database_name,
:username => owner.database_username,
:file => import_from_file
}
)
raise e
end
@ -205,7 +214,7 @@ class Table < Sequel::Model(:user_tables)
def tags=(value)
self[:tags] = value.split(',').map{ |t| t.strip }.compact.delete_if{ |t| t.blank? }.uniq.join(',')
end
def infowindow=(value)
$tables_metadata.hset(key, 'infowindow', value)
end
@ -257,9 +266,9 @@ class Table < Sequel::Model(:user_tables)
owner.in_database.schema(self.name, options.slice(:reload)).each do |column|
next if column[0] == THE_GEOM_WEBMERCATOR
col_db_type = column[1][:db_type].starts_with?("geometry") ? "geometry" : column[1][:db_type]
col = [ column[0],
(options[:cartodb_types] == false) ? col_db_type : col_db_type.convert_to_cartodb_type,
col_db_type == "geometry" ? "geometry" : nil,
col = [ column[0],
(options[:cartodb_types] == false) ? col_db_type : col_db_type.convert_to_cartodb_type,
col_db_type == "geometry" ? "geometry" : nil,
col_db_type == "geometry" ? the_geom_type : nil
].compact
@ -571,13 +580,13 @@ TRIGGER
host = db_configuration['host'] ? "-h #{db_configuration['host']}" : ""
port = db_configuration['port'] ? "-p #{db_configuration['port']}" : ""
username = db_configuration['username']
command = "#{pgsql2shp_bin} #{host} #{port} -u #{username} -f #{shp_file_path} #{database_name} #{self.name}"
system("rm -rf #{all_files_path}")
Rails.logger.info "Executing command: #{command}"
puts `#{command}`
if $?.success?
Zip::ZipFile.open(zip_file_path, Zip::ZipFile::CREATE) do |zipfile|
Dir.glob(Rails.root.join('tmp',"#{shp_files_name}.*").to_s).each do |f|
@ -790,4 +799,4 @@ SQL
@name_changed_from = nil
end
end
end

@ -1,5 +1,4 @@
if Rails.env.production? && APP_CONFIG[:airbrake_api_key].present?
puts APP_CONFIG[:airbrake_api_key]
if APP_CONFIG[:airbrake_api_key].present?
Airbrake.configure do |config|
config.api_key = APP_CONFIG[:airbrake_api_key]
end

@ -24,7 +24,7 @@ if Rails.env.development?
## Development demo data for admin@example.com
user = admin
user = User[:email => 'admin@example.com']
2.times do
t = Table.new :name => "Table #{rand(1000)}"
@ -57,4 +57,4 @@ if Rails.env.development?
table.reload
table.georeference_from!(:latitude_column => :latitude, :longitude_column => :longitude)
end
end

Loading…
Cancel
Save