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 exec "rake" # .bat on Windows 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(exec, 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(exec, RAILS_ROOT, cl) end 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 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 content end end