require 'rake' require 'rake/tasklib' require 'fileutils' module MuckRaker class Tasks < ::Rake::TaskLib def initialize define end private def define namespace :muck do namespace :raker do namespace :db do desc "Flags the languages that the recommender supports" task :populate => :environment do require 'active_record/fixtures' ['en', 'es', 'zh-CN', 'fr', 'ja', 'de', 'ru', 'nl'].each{|l| r = Language.first(:one, :conditions => "locale = '#{l}'") if r r.update_attribute(:muck_raker_supported, true) else puts "Unable to find languages to flag. You probably need to run rake muck:db:populate" break end } # set up the defined services ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym) Fixtures.new(Service.connection,"services",Service,File.join(__FILE__, '..', '..', 'db', 'bootstrap', 'services')).insert_fixtures end desc "Loads oai endpoints so we can get test data" task :bootstrap => :environment do require 'active_record/fixtures' ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym) # import the bootstrap db entries OaiEndpoint.delete_all Fixtures.new(OaiEndpoint.connection,"oai_endpoints",OaiEndpoint,File.join(__FILE__, '..', '..', 'db', 'bootstrap',"oai_endpoints")).insert_fixtures Feed.delete_all Fixtures.new(Feed.connection,"feeds",Feed,File.join(__FILE__, '..', '..', 'db', 'bootstrap',"feeds")).insert_fixtures end end desc "Sync files from recommender." task :sync do path = File.join(File.dirname(__FILE__), *%w[.. ..]) system "rsync -ruv #{path}/db ." system "rsync -ruv #{path}/config/solr ./config" end desc "Start the recommender daemon process" task :start => :environment do require File.expand_path("#{File.dirname(__FILE__)}/../../config/muck_raker_environment") separator = (RUBY_PLATFORM =~ /(win|w)32$/ ? ';' : ':') Dir.chdir(File.join(File.dirname(__FILE__), '../../', 'raker', 'lib')) do jars = Dir['*.jar'].join(separator) options = "-Dsolr.solr.home=\"#{SOLR_CONFIG_PATH}\" -Dsolr.data.dir=\"#{SOLR_DATA_PATH}\" -DRAILS_DB_CONFIG=\"#{RAILS_DB_CONFIG}\" -DLOG_FILE_PREFIX=\"#{LOG_FILE_PREFIX}\" " options << "-DDEBUG " unless (RAILS_ENV == "production" && !ENV['DEBUG']) options << "-DLOG_TO_CONSOLE " unless (RAILS_ENV == "production" && !ENV['DEBUG']) options << "-DFEED_ARCHIVE_PATH=\"#{FEED_ARCHIVE_PATH}\" " classpath = "-classpath #{jars}#{separator}. " javaclass = "edu.usu.cosl.recommenderd.Recommender" cmd = "java " + options + classpath + javaclass puts ("Executing: " + cmd) if ENV['DEBUG'] exec cmd end end desc "Harvest without recommending" task :harvest => :environment do require File.expand_path("#{File.dirname(__FILE__)}/../../config/muck_raker_environment") separator = (RUBY_PLATFORM =~ /(win|w)32$/ ? ';' : ':') Dir.chdir(File.join(File.dirname(__FILE__), '../../', 'raker', 'lib')) do jars = Dir['*.jar'].join(separator) options = "-Dsolr.solr.home=\"#{SOLR_CONFIG_PATH}\" -Dsolr.data.dir=\"#{SOLR_DATA_PATH}\" -DRAILS_DB_CONFIG=\"#{RAILS_DB_CONFIG}\" -DLOG_FILE_PREFIX=\"#{LOG_FILE_PREFIX}\" " options << "-DDEBUG " unless (RAILS_ENV == "production" && !ENV['DEBUG']) options << "-DLOG_TO_CONSOLE " unless (RAILS_ENV == "production" && !ENV['DEBUG']) options << "-DFEED_ARCHIVE_PATH=\"#{FEED_ARCHIVE_PATH}\" " classpath = "-classpath #{jars}#{separator}. " javaclass = "edu.usu.cosl.aggregatord.Harvester" cmd = "java " + options + classpath + javaclass puts ("Executing: " + cmd) if ENV['DEBUG'] exec cmd end end desc "Recommend without harvesting" task :recommend => :environment do require File.expand_path("#{File.dirname(__FILE__)}/../../config/muck_raker_environment") separator = (RUBY_PLATFORM =~ /(win|w)32$/ ? ';' : ':') Dir.chdir(File.join(File.dirname(__FILE__), '../../', 'raker', 'lib')) do jars = Dir['*.jar'].join(separator) options = "-Dsolr.solr.home=\"#{SOLR_CONFIG_PATH}\" -Dsolr.data.dir=\"#{SOLR_DATA_PATH}\" -DRAILS_DB_CONFIG=\"#{RAILS_DB_CONFIG}\" -DLOG_FILE_PREFIX=\"#{LOG_FILE_PREFIX}\" " options << "-DDEBUG " unless (RAILS_ENV == "production" && !ENV['DEBUG']) options << "-DLOG_TO_CONSOLE " unless (RAILS_ENV == "production" && !ENV['DEBUG']) options << "-DFEED_ARCHIVE_PATH=\"#{FEED_ARCHIVE_PATH}\" " classpath = "-classpath #{jars}#{separator}. " javaclass = "edu.usu.cosl.recommenderd.Recommender " cmdlineoption = "skip_harvest " cmd = "java " + options + classpath + javaclass + cmdlineoption puts ("Executing: " + cmd) if ENV['DEBUG'] exec cmd end end desc "Stop the recommender daemon process" task :stop do system "java" end desc "Restart the recommender daemon process" task :restart do system "java" end end end end end end MuckRaker::Tasks.new