Sketch out how to use the jobs queue for trace insertion and deletion
Refs #1852
This commit is contained in:
parent
fbbabeff1e
commit
e59f1b6108
8 changed files with 52 additions and 82 deletions
|
@ -1,59 +0,0 @@
|
|||
#!/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
|
|
@ -1,23 +0,0 @@
|
|||
#!/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
|
Loading…
Add table
Add a link
Reference in a new issue