]> git.openstreetmap.org Git - rails.git/blobdiff - lib/daemons/gpx_import.rb
various things from TomH
[rails.git] / lib / daemons / gpx_import.rb
index c3cd9b06b414b56998a3ff9b96df418e7095b93e..3b7fb02e2fb1bf52453eb907565bb0b478f45cc4 100755 (executable)
@@ -1,19 +1,28 @@
 #!/usr/bin/env ruby
 
 #You might want to change this
-ENV["RAILS_ENV"] ||= "production"
+#ENV["RAILS_ENV"] ||= "development"
 
 require File.dirname(__FILE__) + "/../../config/environment"
 
-$running = true;
-Signal.trap("TERM") do 
-  $running = false
-end
+terminated = false
+
+logger = ActiveRecord::Base.logger
+
+while(true) do
+  ActiveRecord::Base.logger.info("GPX Import daemon wake @ #{Time.now}.")
+
+  Trace.find(:all, :conditions => ['inserted = ?', false]).each do |trace|
+    Signal.trap("TERM") do 
+      terminated = true
+    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
+    trace.import
+
+    Signal.trap("TERM", "DEFAULT")
+
+    exit if terminated
+  end
+
+  sleep 15.minutes
+end