Sha256: 55f4e6872712edab65ed5352c35a0cd34b9ef64015ccc1336982c0261c3a0676

Contents?: true

Size: 1.96 KB

Versions: 9

Compression:

Stored size: 1.96 KB

Contents

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

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
six-updater-web-0.13.2 lib/app/models/system_setting.rb
six-updater-web-0.13.1 lib/app/models/system_setting.rb
six-updater-web-0.12.7 lib/app/models/system_setting.rb
six-updater-web-0.12.6 lib/app/models/system_setting.rb
six-updater-web-0.12.5 lib/app/models/system_setting.rb
six-updater-web-0.12.4 lib/app/models/system_setting.rb
six-updater-web-0.12.3 lib/app/models/system_setting.rb
six-updater-web-0.12.2 lib/app/models/system_setting.rb
six-updater-web-0.12.1 lib/app/models/system_setting.rb