jam-cloud/lib/jam_ruby/tire_tasks.rb

51 lines
1.5 KiB
Ruby

class TireTasks
class << self
@@log = Logging.logger[TireTasks]
end
def self.verify
db_users_count = User.count(:id)
db_bands_count = Band.count(:id)
s = Tire.search [User.index_name], :search_type => 'count', :query => {"match_all" => {}} do
end
es_users_count = s.results.total
s = Tire.search [Band.index_name], :search_type => 'count', :query => {"match_all" => {}} do
end
es_bands_count = s.results.total
@@log.debug "database_users=#{db_users_count}, elasticsearch_users=#{es_users_count} database_bands=#{db_bands_count}, elasticsearch_bands=#{es_bands_count} "
if db_users_count != es_users_count
@@log.error "the number of elasticsearch users (#{es_users_count}) != the number of database users ((#{db_users_count}). A rebuild of the elasticsearch index should be performed"
return false
end
if db_bands_count != es_bands_count
@@log.error "the number of elasticsearch bands (#{es_bands_count}) != the number of database bands (#{db_bands_count}). A rebuild of the elasticsearch index should be performed"
return false
end
return true
end
def self.rebuild_indexes
@@log.info "rebuilding elasticsearch"
User.delete_search_index
User.create_search_index
Band.delete_search_index
Band.create_search_index
User.import :per_page => 100
Band.import :per_page => 100
@@log.info "done rebuilding elasticsearch"
User.search_index.refresh
Band.search_index.refresh
end
end