[openstreetmap/openstreetmap-website] Integrate the high-performance GPX importer (#1852)

mmd notifications at github.com
Thu Oct 4 19:57:55 UTC 2018


> That said the daemon code may well just need a rewrite - it was based around an ancient rails feature for running daemons that I suspect is long since abandoned and we likely want something based on ActiveJob or something now.

I tried the following for ActiveJob:

`rails generate job GPXUpdater`

Moved some of the code from gpx_import.rb to one of the newly generated file gpx_updater_job.rb:

```ruby
logger = ActiveRecord::Base.logger

class GpxUpdaterJob < ApplicationJob
  queue_as :default

  def perform(id)
    ActiveRecord::Base.logger.info("GPX Import daemon wake @ #{Time.now}.")

    trace = Trace.find(id)

    begin
      gpx = trace.import

      if gpx.actual_points.positive?
        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
        trace.destroy
      end
    rescue StandardError => ex
      print (ex.to_s)
      logger.info ex.to_s
      ex.backtrace.each { |l| logger.info l }
      Notifier.gpx_failure(trace, ex.to_s + "\n" + ex.backtrace.join("\n")).deliver
      trace.destroy
    end
  end
end
```

and finally added one line to the traces_controller.rb run run `GpxUpdaterJob.perform_later(trace.id)`

```ruby
          # Pass the exception on
          raise
        end
      end

      GpxUpdaterJob.perform_later(trace.id)
    end
  
    # Finally save the user's preferred privacy level
    if pref = current_user.preferences.where(:k => "gps.trace.visibility").first
      pref.v = visibility
      pref.save
    else
```

Creating icons didn't work for whatever reason, and I had to comment them out in trace.rb:


-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/issues/1852#issuecomment-427149334
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20181004/90949fef/attachment.html>


More information about the rails-dev mailing list