class SystemSetting < ActiveRecord::Base TIMEOUT = 20 def self.singleton system_setting = self.find(:first) if system_setting system_setting else self.new end end def path path = SixUpdaterWeb::RUBY_PATH.clone path.gsub!("/", "\\") end def app_path "rake" end def update_gamespy self.gamespied_at = Time.now self.save cl = "sync:gamespy RAILS_ENV=#{ENV['RAILS_ENV']} BASE_PATH=\'#{SixUpdaterWeb::BASE_PATH}\'" # + cl SixUpdaterWeb.run_program(path, app_path, RAILS_ROOT, cl) end def update_gamespy_nogeo self.gamespied_at = Time.now self.save cl = "sync:gamespy RAILS_ENV=#{ENV['RAILS_ENV']} NOGEO=1 BASE_PATH=\'#{SixUpdaterWeb::BASE_PATH}\'" # + cl SixUpdaterWeb.run_program(path, app_path, RAILS_ROOT, cl) end #system "tools/ruby/bin/ruby tools/ruby/bin/rake sync:gamespy" #path = File.join(SixUpdaterWeb::BASE_PATH, 'tools', "ruby", "bin") #path = File.join("C:", "Ruby", "Bin") #path.gsub!("/", "\\") # \"#{path}\\rake\" def synchronize Six::Network::Panel.setlogger(logger) l = [] begin status = Timeout::timeout(TIMEOUT) do Six::Network::Panel.login(self.server_username, self.server_password, true) end [Network, Mod, Server, Repository, Action, Appsetting, Sixconfig].each do |t| l += t.imp end rescue Timeout::Error logger.info "TIMEOUT while trying to synchronize!" rescue logger.info "ERROR: #{$!}" end l end def sync self.synchronized_at = Time.now self.save content = nil #begin l = self.synchronize if l.size > 0 content = "Synchronized #{l.size} records with server-site!" #l.map {|e| e.to_json}.join(", ") else content = "WARNING: No objects received, possibly issue with connection (timeout?), or server site" end # rescue # logger.debug "#{$!}" # content = "ERROR: Failed synchronization: #{$!}" #end content end end