]> git.openstreetmap.org Git - rails.git/blob - app/jobs/trace_importer_job.rb
Don't include stack backtraces on xml errors when importing traces
[rails.git] / app / jobs / trace_importer_job.rb
1 class TraceImporterJob < ApplicationJob
2   queue_as :traces
3
4   def perform(trace)
5     gpx = trace.import
6
7     if gpx.actual_points.positive?
8       UserMailer.gpx_success(trace, gpx.actual_points).deliver
9     else
10       UserMailer.gpx_failure(trace, "0 points parsed ok. Do they all have lat,lng,alt,timestamp?").deliver
11       trace.destroy
12     end
13   rescue XML::Error => e
14     logger.info e.to_s
15     UserMailer.gpx_failure(trace, e).deliver
16     trace.destroy
17   rescue StandardError => e
18     logger.info e.to_s
19     e.backtrace.each { |l| logger.info l }
20     UserMailer.gpx_failure(trace, "#{e}\n#{e.backtrace.join("\n")}").deliver
21     trace.destroy
22   end
23 end