flash[:notice] = t ".trace_uploaded"
flash[:warning] = t ".traces_waiting", :count => current_user.traces.where(:inserted => false).count if current_user.traces.where(:inserted => false).count > 4
+ TraceImporterJob.perform_later(@trace)
redirect_to :action => :index, :display_name => current_user.display_name
else
flash[:error] = t("traces.create.upload_failed") if @trace.valid?
trace.visible = false
trace.save
flash[:notice] = t ".scheduled_for_deletion"
+ TraceDestroyerJob.perform_later(trace)
redirect_to :action => :index, :display_name => trace.user.display_name
end
rescue ActiveRecord::RecordNotFound
--- /dev/null
+class ApplicationJob < ActiveJob::Base
+ # Automatically retry jobs that encountered a deadlock
+ # retry_on ActiveRecord::Deadlocked
+
+ # Most jobs are safe to ignore if the underlying records are no longer available
+ # discard_on ActiveJob::DeserializationError
+end
--- /dev/null
+class TraceDestroyerJob < ApplicationJob
+ queue_as :default
+
+ def perform(trace)
+ trace.destroy
+ rescue StandardError => ex
+ logger.info ex.to_s
+ ex.backtrace.each { |l| logger.info l }
+ end
+end
--- /dev/null
+class TraceImporterJob < ApplicationJob
+ queue_as :default
+
+ def perform(trace)
+ gpx = trace.import
+
+ if gpx.actual_points.positive?
+ Notifier.gpx_success(trace, gpx.actual_points).deliver_later
+ else
+ Notifier.gpx_failure(trace, "0 points parsed ok. Do they all have lat,lng,alt,timestamp?").deliver_later
+ trace.destroy
+ end
+ rescue StandardError => ex
+ 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_later
+ trace.destroy
+ end
+end
+++ /dev/null
-#!/usr/bin/env ruby
-
-# You might want to change this
-# ENV["RAILS_ENV"] ||= "development"
-
-require File.dirname(__FILE__) + "/../../config/environment"
-
-terminated = false
-
-logger = ActiveRecord::Base.logger
-
-loop do
- ActiveRecord::Base.logger.info("GPX Import daemon wake @ #{Time.now}.")
-
- 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.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
- 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
-
- Signal.trap("TERM", "DEFAULT")
-
- exit if terminated
- end
-
- Trace.find(:all, :conditions => { :visible => false }, :order => "id").each do |trace|
- Signal.trap("TERM") do
- terminated = true
- end
-
- begin
- trace.destroy
- rescue StandardError => ex
- logger.info ex.to_s
- ex.backtrace.each { |l| logger.info l }
- end
-
- Signal.trap("TERM", "DEFAULT")
-
- exit if terminated
- end
-
- sleep 5.minutes.value
-end
+++ /dev/null
-#!/usr/bin/env ruby
-require "rubygems"
-require "daemons"
-require "yaml"
-require "erb"
-
-class Hash
- def with_symbols!
- each_key { |key| self[key.to_s.to_sym] = self[key] }
- self
- end
-end
-
-options = YAML.safe_load(
- ERB.new(
- IO.read(
- File.dirname(__FILE__) + "/../../config/daemons.yml"
- )
- ).result
-).with_symbols!
-options[:dir_mode] = options[:dir_mode].to_sym
-
-Daemons.run File.dirname(__FILE__) + "/gpx_import.rb", options
--- /dev/null
+require 'test_helper'
+
+class TraceDestroyerJobTest < ActiveJob::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
--- /dev/null
+require 'test_helper'
+
+class TraceImporterJobTest < ActiveJob::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end