namespace :sync do task :records => :environment do system_setting = SystemSetting.singleton puts system_setting.sync end task :gamespy => :environment do puts "Fetching server info..." geo = ENV['NOGEO'] ? "" : nil #geo = "" puts "Pings and Countries: #{geo.nil?}" puts "" q = Six::Query::GamespyMaster.new(geo) h = q.process puts "" puts "Received #{h.size} servers" puts "" puts "Updating database..." i, saved = 0, 0 ids = [] #hasj = Hash.new timestart = Time.now h.each_pair do |key, e| i += 1 time = Time.now r = Queryserver.import(e) next unless r if r[0].changed? #hasj[r[0].id] = r[1] saved += 1 r[0].save else ids << r[0].id end print "#{i} / #{h.keys.size}, took #{SixUpdaterWeb::stamp(time)}s\r" end puts "Saved: #{saved}, Unchanged: #{h.keys.size - saved}. Took: #{SixUpdaterWeb::stamp(timestart)}s" =begin timestart = Time.now puts "Updating #{hasj.keys.size} records..." begin Queryserver.update(hasj.keys, hasj.values) unless hasj.keys.empty? rescue => e puts "#{e.class}: #{e.message} #{e.backtrace.join("\n")}" sleep 3 ensure puts "Took: #{SixUpdaterWeb::stamp(timestart)}s" end =end timestart = Time.now puts "Tagging... #{ids.size} records" begin Queryserver.update_all("updated_at = '#{Time.now}'", ["id in (?)",ids]) unless ids.empty? rescue => e puts "#{e.class}: #{e.message} #{e.backtrace.join("\n")}" ensure puts "Took: #{SixUpdaterWeb::stamp(timestart)}s" end puts "Pruning database..." timestart = Time.now Queryserver.prune puts "Took: #{SixUpdaterWeb::stamp(timestart)}s" puts "Cleaning database..." timestart = Time.now Queryserver.clean puts "Took: #{SixUpdaterWeb::stamp(timestart)}s" puts "" puts "Done!" sleep 3 end task :system => :environment do Six::Dbmanager.reload_system end task :data => :environment do Six::Dbmanager.reload_data end task :integrated => :environment do Sixconfig.start_updater_inweb("--install") end end task :export => :environment do if ENV.include?("preset") config = Sixconfig.find(ENV['preset'].to_i) File.open(File.join(SixUpdaterWeb::DATA_PATH, 'six-updater.yml'), 'w') do |file| file.puts config.to_updater_yml end else puts "Error: No preset selected" end end