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



67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/six-updater-web/app/models/system_setting.rb', line 67

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



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/six-updater-web/app/models/system_setting.rb', line 43

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
    # Temporary until migration done
    begin
      l += Category.imp
    rescue => e
      logger.info "ERROR: #{e.class} #{e.message} #{e.backtrace.join("\n")}"
    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_gamespy(internal = false) ⇒ Object



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

def update_gamespy(internal = false)
  self.gamespied_at = Time.now
  self.save
  ENV['NOGEO'] = nil
  if internal
    SixUpdaterWeb.update_gamespy
  else
    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
end

#update_gamespy_nogeo(internal = false) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/six-updater-web/app/models/system_setting.rb', line 30

def update_gamespy_nogeo(internal = false)
  self.gamespied_at = Time.now
  self.save
  ENV['NOGEO'] = "1"
  if internal
    SixUpdaterWeb.update_gamespy
  else
    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
end