]> git.openstreetmap.org Git - rails.git/blobdiff - lib/daemons/gpx_import.rb
various gpx bits
[rails.git] / lib / daemons / gpx_import.rb
index c3cd9b06b414b56998a3ff9b96df418e7095b93e..015a2791648451ae0555ad8c1a2de53a9a2ae517 100755 (executable)
@@ -1,7 +1,7 @@
 #!/usr/bin/env ruby
 
 #You might want to change this
-ENV["RAILS_ENV"] ||= "production"
+ENV["RAILS_ENV"] ||= "development"
 
 require File.dirname(__FILE__) + "/../../config/environment"
 
@@ -12,8 +12,26 @@ end
 
 while($running) do
   
-  # Replace this with your code
-  ActiveRecord::Base.logger << "This daemon is still running at #{Time.now}.\n"
-  
-  sleep 10
-end
\ No newline at end of file
+  ActiveRecord::Base.logger.info("GPX Import daemon wake @ #{Time.now}.")
+
+  traces = Trace.find(:all, :conditions => ['inserted = ?', false])
+
+  if traces and traces.length > 0
+    traces.each do |trace|
+      begin
+
+        ActiveRecord::Base.logger.info("GPX Import importing #{trace.name} from #{trace.user.email}")
+
+        #  gpx = OSM::GPXImporter.new('/tmp/2.gpx')
+        #  gpx.points do |point|
+        #    puts point['latitude']
+        #  end
+        
+        Notifier::deliver_gpx_success(trace)
+      rescue
+        Notifier::deliver_gpx_failure(trace)
+      end
+    end
+  end
+  sleep 15.minutes
+end