Class: SystemSetting

Inherits:
ActiveRecord::Base show all
Defined in:
lib/six-updater-web/app/models/system_setting.rb

Constant Summary collapse

TIMEOUT =
20

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ActiveRecord::Base

#associated_valid?, #no_errors_in_associated?, #save_associated, #save_associated!, #save_with_unsaved_flag, #to_label, #unsaved=, #unsaved?

Class Method Details

.singletonObject



4
5
6
7
8
9
10
11
# File 'lib/six-updater-web/app/models/system_setting.rb', line 4

def self.singleton
  system_setting = self.find(:first)
  if system_setting
    system_setting
  else
    self.new
  end
end

Instance Method Details

#execObject



13
14
15
# File 'lib/six-updater-web/app/models/system_setting.rb', line 13

def exec
  "rake" # .bat on Windows
end

#syncObject



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/six-updater-web/app/models/system_setting.rb', line 51

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

#synchronizeObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/six-updater-web/app/models/system_setting.rb', line 33

def synchronize
  Six::Network::Panel.setlogger(logger)
  l = []
  begin
    status = Timeout::timeout(TIMEOUT) do
      Six::Network::Panel.(self.server_username, self.server_password, true)
    end
    [Mod, Network, Server, Repository, Action, Appsetting, Sixconfig].each do |t|
      l += t.imp
    end
  rescue Timeout::Error
    logger.info "TIMEOUT while trying to synchronize!"
  rescue => e
    logger.info "ERROR: #{e.class} #{e.message} #{e.backtrace.join("\n")}"
  end
  l
end

#update_gamespyObject



17
18
19
20
21
22
23
# File 'lib/six-updater-web/app/models/system_setting.rb', line 17

def update_gamespy
  self.gamespied_at = Time.now
  self.save
  cl = "sync:gamespy RAILS_ENV=#{ENV['RAILS_ENV']}" # + cl
  cl += " BASE_PATH=\'#{SixUpdaterWeb::BASE_PATH}\'" if defined?(SixUpdaterWeb::OLDLOCATION)
  SixUpdaterWeb.run_program(exec, RAILS_ROOT, cl)
end

#update_gamespy_nogeoObject



25
26
27
28
29
30
31
# File 'lib/six-updater-web/app/models/system_setting.rb', line 25

def update_gamespy_nogeo
  self.gamespied_at = Time.now
  self.save
  cl = "sync:gamespy RAILS_ENV=#{ENV['RAILS_ENV']} NOGEO=1" # + cl
  cl += " BASE_PATH=\'#{SixUpdaterWeb::BASE_PATH}\'" if defined?(SixUpdaterWeb::OLDLOCATION)
  SixUpdaterWeb.run_program(exec, RAILS_ROOT, cl)
end