source: subversion/sites/rails_port/lib/daemons/gpx_import.rb @ 4274

Last change on this file since 4274 was 4274, checked in by tomhughes, 13 years ago

Put the option to delete GPS traces back. Fixes #405.

  • Property svn:executable set to *
File size: 1.3 KB
Line 
1#!/usr/bin/env ruby
2
3#You might want to change this
4#ENV["RAILS_ENV"] ||= "development"
5
6require File.dirname(__FILE__) + "/../../config/environment"
7
8terminated = false
9
10logger = ActiveRecord::Base.logger
11
12while(true) do
13  ActiveRecord::Base.logger.info("GPX Import daemon wake @ #{Time.now}.")
14
15  Trace.find(:all, :conditions => 'inserted = 0').each do |trace|
16    Signal.trap("TERM") do 
17      terminated = true
18    end
19
20    begin
21      gpx = trace.import
22
23      if gpx.actual_points > 0
24        Notifier::deliver_gpx_success(trace, gpx.actual_points)
25      else
26        trace.destroy
27        Notifier::deliver_gpx_failure(trace, '0 points parsed ok. Do they all have lat,lng,alt,timestamp?')
28      end
29    rescue Exception => ex
30      logger.info ex.to_s
31      ex.backtrace.each {|l| logger.info l }
32      trace.destroy
33      Notifier::deliver_gpx_failure(trace, ex.to_s + "\n" + ex.backtrace.join("\n"))
34    end
35
36    Signal.trap("TERM", "DEFAULT")
37
38    exit if terminated
39  end
40
41  Trace.find(:all, :conditions => 'visible = 0').each do |trace|
42    Signal.trap("TERM") do 
43      terminated = true
44    end
45
46    begin
47      trace.destroy
48    rescue Exception => ex
49      logger.info ex.to_s
50      ex.backtrace.each {|l| logger.info l }
51    end
52
53    Signal.trap("TERM", "DEFAULT")
54
55    exit if terminated
56  end
57
58  sleep 5.minutes
59end
Note: See TracBrowser for help on using the repository browser.