- traces = Trace.find(:all, :conditions => ['inserted = ?', false])
-
- if traces and traces.length > 0
- traces.each do |trace|
- begin
-
- logger.info("GPX Import importing #{trace.name} from #{trace.user.email}")
-
- gzipped = `file -b /tmp/#{trace.id}.gpx`.chomp =~/^gzip/
-
- if gzipped
- logger.info("gzipped")
- else
- logger.info("not gzipped")
- end
- gpx = OSM::GPXImporter.new("/tmp/#{trace.id}.gpx")
-
- gpx.points do |point|
- tp = Tracepoint.new
- tp.latitude = point['latitude']
- tp.latitude = point['longitude']
- tp.altitude = point['altitude']
- tp.user_id = trace.user.id
- tp.gpx_id = trace.id
- tp.trackid = point['segment']
- end
- trace.size = gpx.actual_points
- trace.inserted = true
- trace.save
- Notifier::deliver_gpx_success(trace, gpx.possible_points)
- rescue Exception => ex
+ Trace.find(:all, :conditions => { :inserted => false, :visible => true }, :order => "id").each do |trace|
+ Signal.trap("TERM") do
+ terminated = true
+ end
+
+ begin
+ gpx = trace.import
+
+ if gpx.actual_points > 0
+ Notifier.gpx_success(trace, gpx.actual_points).deliver
+ else
+ Notifier.gpx_failure(trace, "0 points parsed ok. Do they all have lat,lng,alt,timestamp?").deliver