# desc "Explaining what the task does" # task :sports_db do # # Task goes here # end namespace 'zu' do task :set_logger => :environment do RAILS_DEFAULT_LOGGER = Logger.new(STDOUT) end namespace 'sports' do desc "Run sports db migrations." task :migrate => 'zu:set_logger' do ActiveRecord::Migration.verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true ActiveRecord::Migrator.migrate("vendor/plugins/sports_db/db/migrate/", ENV["VERSION"] ? ENV["VERSION"].to_i : nil) Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby end desc "Drops and recreates the sports_db database (as well as any application-specific migrations)." task :reset => [ 'db:drop', 'db:create', 'zu:sports:migrate', 'db:migrate'] do # Renamed this reset because there's a db:reset task that does the same thing... end desc "Incrementally update the database based on job's frequency. Usage: 'rake zu:sports:update[1]'" task :update, [:frequency] => 'zu:set_logger' do |t, args| case args.frequency when "1" then SportsBuildManager.every_1_minute when "15" then SportsBuildManager.every_15_minutes when "60" then SportsBuildManager.every_60_minutes when "720" then SportsBuildManager.every_720_minutes when "1440" then SportsBuildManager.every_1440_minutes end end desc "Run game_updater (sub-1 minute task)" task :run_games_updater, [] => ['zu:set_logger'] do |t| SportsBuildManager.games_updater end desc "Build the entire database 'from scratch' without reference to job scheduling" task :build, [] => ['zu:set_logger'] do |t| %w(one_time every_1440_minutes every_720_minutes every_15_minutes every_1_minute).each do |m| SportsBuildManager.send(m) end end desc "Run one time and 12 hour builds prior to starting FeedFetcher on a clean instance of TSN server" task :build_to_day, [] => ['zu:set_logger'] do |t| SportsBuildManager.one_time SportsBuildManager.every_1440_minutes end desc "Parse team info xml from sporting news and fetch all team logos to local disk." task :get_team_logos => 'zu:set_logger' do mkdir "#{Rails.root.to_s}/public/images/logos/" unless File.exists?( "#{Rails.root.to_s}/public/images/logos/" ) config = SimpleConfig.for(:feeds) require 'open-uri' open( config.team_info_url ) do |file| doc = Nokogiri::XML(file.read) doc.xpath('//row').each do |team_element| %w{small medium large}.each do |size| image = open( team_element['TEAM_LOGO'].gsub( /large/, size ) ) path = "#{Rails.root.to_s}/public/images/logos/#{size}" mkdir path unless File.exists?( path ) /\.(\w+)$/ =~ team_element['TEAM_LOGO'] File.open("#{path}/#{team_element['TEAM_NAME_SHORT']}.#{$1}", "w") do |file| file.puts( image.read ) end end end end end desc "Set up Stats LLC database, same schema as the mlb database, just with a different name, for testing" task :create_statsllc_database => 'zu:set_logger' do ActiveRecord::Base.configurations = YAML::load(IO.read("#{Rails.root.to_s}/config/statsllc_database.yml")) ActiveRecord::Base.establish_connection("#{Rails.env}") ActiveRecord::Base.connection.drop_database(ActiveRecord::Base.configurations[Rails.env]["database"]) ActiveRecord::Base.connection.create_database(ActiveRecord::Base.configurations[Rails.env]["database"], ActiveRecord::Base.configurations[Rails.env]) ActiveRecord::Base.establish_connection("#{Rails.env}") ActiveRecord::Migration.verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true ActiveRecord::Migrator.migrate("vendor/plugins/sports_db/db/migrate/", ENV["VERSION"] ? ENV["VERSION"].to_i : nil) ActiveRecord::Migrator.migrate("db/migrate/", ENV["VERSION"] ? ENV["VERSION"].to_i : nil) end desc "Run migrations on statsllc db" task :migrate_statsllc_database => 'zu:set_logger' do ActiveRecord::Base.configurations = YAML::load(IO.read("#{Rails.root.to_s}/config/statsllc_database.yml")) ActiveRecord::Base.establish_connection("#{Rails.env}") ActiveRecord::Migration.verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true ActiveRecord::Migrator.migrate("vendor/plugins/sports_db/db/migrate/", ENV["VERSION"] ? ENV["VERSION"].to_i : nil) ActiveRecord::Migrator.migrate("db/migrate/", ENV["VERSION"] ? ENV["VERSION"].to_i : nil) end end end