Skip to content

Commit

Permalink
Adds silence option to argument array, and better matching to answer
Browse files Browse the repository at this point in the history
This commit adds a silence option for users that have automated this
task and want to skip the destructive prompt. It also changes the
matching of a user's answer to explicitally check for 'y'.
  • Loading branch information
mkrisher committed Feb 27, 2013
1 parent 3cb90de commit 57ce883
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions sunspot_rails/lib/sunspot/rails/tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@
# $ rake sunspot:reindex[1000,Post] # reindex only the Post model in
# # batchs of 1000
# $ rake sunspot:reindex[,Post+Author] # reindex Post and Author model
task :reindex, [:batch_size, :models] => [:environment] do |t, args|
puts "*Note: the reindex task will remove your current indexes and start from scratch."
puts "If you have a large dataset, reindexing can take a very long time, possibly weeks."
puts "This is not encouraged if you have anywhere near or over 1 million rows."
puts "Are you sure you want to drop your indexes and completely reindex? (y/n)"
answer = STDIN.gets.chomp
return false if answer == "n"
# $ rake sunspot:reindex[,,true] # reindex silencing/skipping the boolean prompt
task :reindex, [:batch_size, :models, :silence] => [:environment] do |t, args|
args.with_defaults(:silence => false)
if args[:silence] == false
puts "*Note: the reindex task will remove your current indexes and start from scratch."
puts "If you have a large dataset, reindexing can take a very long time, possibly weeks."
puts "This is not encouraged if you have anywhere near or over 1 million rows."
puts "Are you sure you want to drop your indexes and completely reindex? (y/n)"
answer = STDIN.gets.chomp
return false unless answer.match(/^y/)
end

# Retry once or gracefully fail for a 5xx error so we don't break reindexing
Sunspot.session = Sunspot::SessionProxy::Retry5xxSessionProxy.new(Sunspot.session)
Expand Down

0 comments on commit 57ce883

Please sign in to comment.