<blockquote>
<p>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.</p>
</blockquote>
<p>I tried the following for ActiveJob:</p>
<p><code>rails generate job GPXUpdater</code></p>
<p>Moved some of the code from gpx_import.rb to one of the newly generated file gpx_updater_job.rb:</p>
<div class="highlight highlight-source-ruby"><pre>logger <span class="pl-k">=</span> <span class="pl-c1">ActiveRecord</span>::<span class="pl-c1">Base</span>.logger

<span class="pl-k">class</span> <span class="pl-en">GpxUpdaterJob<span class="pl-e"> < ApplicationJob</span></span>
  queue_as <span class="pl-c1">:default</span>

  <span class="pl-k">def</span> <span class="pl-en">perform</span>(<span class="pl-smi">id</span>)
    <span class="pl-c1">ActiveRecord</span>::<span class="pl-c1">Base</span>.logger.info(<span class="pl-s"><span class="pl-pds">"</span>GPX Import daemon wake @ <span class="pl-pse">#{</span><span class="pl-s1"><span class="pl-c1">Time</span>.now</span><span class="pl-pse">}</span>.<span class="pl-pds">"</span></span>)

    trace <span class="pl-k">=</span> <span class="pl-c1">Trace</span>.find(id)

    <span class="pl-k">begin</span>
      gpx <span class="pl-k">=</span> trace.import

      <span class="pl-k">if</span> gpx.actual_points.positive?
        <span class="pl-c1">Notifier</span>.gpx_success(trace, gpx.actual_points).deliver
      <span class="pl-k">else</span>
        <span class="pl-c1">Notifier</span>.gpx_failure(trace, <span class="pl-s"><span class="pl-pds">"</span>0 points parsed ok. Do they all have lat,lng,alt,timestamp?<span class="pl-pds">"</span></span>).deliver
        trace.destroy
      <span class="pl-k">end</span>
    <span class="pl-k">rescue</span> <span class="pl-c1">StandardError</span> => ex
      <span class="pl-c1">print</span> (ex.to_s)
      logger.info ex.to_s
      ex.backtrace.each { |<span class="pl-smi">l</span>| logger.info l }
      <span class="pl-c1">Notifier</span>.gpx_failure(trace, ex.to_s <span class="pl-k">+</span> <span class="pl-s"><span class="pl-pds">"</span><span class="pl-cce">\n</span><span class="pl-pds">"</span></span> <span class="pl-k">+</span> ex.backtrace.join(<span class="pl-s"><span class="pl-pds">"</span><span class="pl-cce">\n</span><span class="pl-pds">"</span></span>)).deliver
      trace.destroy
    <span class="pl-k">end</span>
  <span class="pl-k">end</span>
<span class="pl-k">end</span></pre></div>
<p>and finally added one line to the traces_controller.rb run run <code>GpxUpdaterJob.perform_later(trace.id)</code></p>
<div class="highlight highlight-source-ruby"><pre>          <span class="pl-c"><span class="pl-c">#</span> Pass the exception on</span>
          <span class="pl-k">raise</span>
        <span class="pl-k">end</span>
      <span class="pl-k">end</span>

      <span class="pl-c1">GpxUpdaterJob</span>.perform_later(trace.id)
    <span class="pl-k">end</span>
  
    <span class="pl-c"><span class="pl-c">#</span> Finally save the user's preferred privacy level</span>
    <span class="pl-k">if</span> pref <span class="pl-k">=</span> current_user.preferences.where(<span class="pl-c1">:k</span> => <span class="pl-s"><span class="pl-pds">"</span>gps.trace.visibility<span class="pl-pds">"</span></span>).first
      pref.v <span class="pl-k">=</span> visibility
      pref.save
    <span class="pl-k">else</span></pre></div>
<p>Creating icons didn't work for whatever reason, and I had to comment them out in trace.rb:</p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/openstreetmap/openstreetmap-website/issues/1852#issuecomment-427149334">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/ABWnLW_odJOL2vomlpQ7KsPzgw-vToGjks5uhmhCgaJpZM4T3-LP">mute the thread</a>.<img src="https://github.com/notifications/beacon/ABWnLTmjvELW1fqoj4dT959wdJLWsU5Xks5uhmhCgaJpZM4T3-LP.gif" height="1" width="1" alt="" /></p>
<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/openstreetmap/openstreetmap-website","title":"openstreetmap/openstreetmap-website","subtitle":"GitHub repository","main_image_url":"https://assets-cdn.github.com/images/email/message_cards/header.png","avatar_image_url":"https://assets-cdn.github.com/images/email/message_cards/avatar.png","action":{"name":"Open in GitHub","url":"https://github.com/openstreetmap/openstreetmap-website"}},"updates":{"snippets":[{"icon":"PERSON","message":"@mmd-osm in #1852: \u003e 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.\r\n\r\nI tried the following for ActiveJob:\r\n\r\n`rails generate job GPXUpdater`\r\n\r\nMoved some of the code from gpx_import.rb to one of the newly generated file gpx_updater_job.rb:\r\n\r\n```ruby\r\nlogger = ActiveRecord::Base.logger\r\n\r\nclass GpxUpdaterJob \u003c ApplicationJob\r\n  queue_as :default\r\n\r\n  def perform(id)\r\n    ActiveRecord::Base.logger.info(\"GPX Import daemon wake @ #{Time.now}.\")\r\n\r\n    trace = Trace.find(id)\r\n\r\n    begin\r\n      gpx = trace.import\r\n\r\n      if gpx.actual_points.positive?\r\n        Notifier.gpx_success(trace, gpx.actual_points).deliver\r\n      else\r\n        Notifier.gpx_failure(trace, \"0 points parsed ok. Do they all have lat,lng,alt,timestamp?\").deliver\r\n        trace.destroy\r\n      end\r\n    rescue StandardError =\u003e ex\r\n      print (ex.to_s)\r\n      logger.info ex.to_s\r\n      ex.backtrace.each { |l| logger.info l }\r\n      Notifier.gpx_failure(trace, ex.to_s + \"\\n\" + ex.backtrace.join(\"\\n\")).deliver\r\n      trace.destroy\r\n    end\r\n  end\r\nend\r\n```\r\n\r\nand finally added one line to the traces_controller.rb run run `GpxUpdaterJob.perform_later(trace.id)`\r\n\r\n```ruby\r\n          # Pass the exception on\r\n          raise\r\n        end\r\n      end\r\n\r\n      GpxUpdaterJob.perform_later(trace.id)\r\n    end\r\n  \r\n    # Finally save the user's preferred privacy level\r\n    if pref = current_user.preferences.where(:k =\u003e \"gps.trace.visibility\").first\r\n      pref.v = visibility\r\n      pref.save\r\n    else\r\n```\r\n\r\nCreating icons didn't work for whatever reason, and I had to comment them out in trace.rb:\r\n"}],"action":{"name":"View Issue","url":"https://github.com/openstreetmap/openstreetmap-website/issues/1852#issuecomment-427149334"}}}</script>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/openstreetmap/openstreetmap-website/issues/1852#issuecomment-427149334",
"url": "https://github.com/openstreetmap/openstreetmap-website/issues/1852#issuecomment-427149334",
"name": "View Issue"
},
"description": "View this Issue on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
},
{
"@type": "MessageCard",
"@context": "http://schema.org/extensions",
"hideOriginalBody": "false",
"originator": "AF6C5A86-E920-430C-9C59-A73278B5EFEB",
"title": "Re: [openstreetmap/openstreetmap-website] Integrate the high-performance GPX importer (#1852)",
"sections": [
{
"text": "",
"activityTitle": "**mmd**",
"activityImage": "https://assets-cdn.github.com/images/email/message_cards/avatar.png",
"activitySubtitle": "@mmd-osm",
"facts": [

]
}
],
"potentialAction": [
{
"name": "Add a comment",
"@type": "ActionCard",
"inputs": [
{
"isMultiLine": true,
"@type": "TextInput",
"id": "IssueComment",
"isRequired": false
}
],
"actions": [
{
"name": "Comment",
"@type": "HttpPOST",
"target": "https://api.github.com",
"body": "{\n\"commandName\": \"IssueComment\",\n\"repositoryFullName\": \"openstreetmap/openstreetmap-website\",\n\"issueId\": 1852,\n\"IssueComment\": \"{{IssueComment.value}}\"\n}"
}
]
},
{
"name": "Close issue",
"@type": "HttpPOST",
"target": "https://api.github.com",
"body": "{\n\"commandName\": \"IssueClose\",\n\"repositoryFullName\": \"openstreetmap/openstreetmap-website\",\n\"issueId\": 1852\n}"
},
{
"targets": [
{
"os": "default",
"uri": "https://github.com/openstreetmap/openstreetmap-website/issues/1852#issuecomment-427149334"
}
],
"@type": "OpenUri",
"name": "View on GitHub"
},
{
"name": "Unsubscribe",
"@type": "HttpPOST",
"target": "https://api.github.com",
"body": "{\n\"commandName\": \"MuteNotification\",\n\"threadId\": 333439695\n}"
}
],
"themeColor": "26292E"
}
]</script>