various gpx bits
[rails.git] / lib / daemons / gpx_import.rb
1 #!/usr/bin/env ruby
2
3 #You might want to change this
4 ENV["RAILS_ENV"] ||= "development"
5
6 require File.dirname(__FILE__) + "/../../config/environment"
7
8 $running = true;
9 Signal.trap("TERM") do 
10   $running = false
11 end
12
13 while($running) do
14   
15   ActiveRecord::Base.logger.info("GPX Import daemon wake @ #{Time.now}.")
16
17   traces = Trace.find(:all, :conditions => ['inserted = ?', false])
18
19   if traces and traces.length > 0
20     traces.each do |trace|
21       begin
22
23         ActiveRecord::Base.logger.info("GPX Import importing #{trace.name} from #{trace.user.email}")
24
25         #  gpx = OSM::GPXImporter.new('/tmp/2.gpx')
26         #  gpx.points do |point|
27         #    puts point['latitude']
28         #  end
29         
30         Notifier::deliver_gpx_success(trace)
31       rescue
32         Notifier::deliver_gpx_failure(trace)
33       end
34     end
35   end
36   sleep 15.minutes
37 end