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

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

Fix exception handling in GPX importer.

  • Property svn:executable set to *
File size: 1015 bytes
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 = ?', false]).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  sleep 5.minutes
42end
Note: See TracBrowser for help on using the repository browser.