Setting bash aliases for IRB?
-
26-09-2019 - |
문제
So every morning to boot up my server , I need to do the following tasks..
>> sunspot-solr stop
>> sunspot-solr start
>> script/console
>> Organization.reindex
>> Event.reindex
>> Deal.reindex
>> exit
>> script/server
Is there any way I can make a shortcut in my ~/.profile as an alias to perform all this for me without me typing it everyday?
Like this though it doesn't work ?
alias blam='cur && sunspot-solr stop && sunspot-solr start && script/console && Organization.reindex && Event.reindex && Deal.reindex && exit && script/server'
해결책
Maybe this will ease some of the pain?
#Rakefile
desc "Reindex the organizations, events, and deals Solr indexes."
task :reindex => :environment do
Organization.reindex
Event.reindex
Deal.reindex
end
Then every morning run
> sunspot-solr stop
> sunspot-solr start
> rake reindex
> script/server
다른 팁
This is my first StackOverflow post and it's a old question, but I felt I could contribute somehow :D Rebuilding the Solr index periodically is a very expensive task, you should avoid doing things like this in production! What you are looking for can be best achieved in three ways:
1 - edit you sunspot.yml and add the line
auto_commit_after_request = true
This will tell sunspot to update the index everytime a new model entry is saved (or deleted). This will keep your index updated but can be expensive.
2 - create a rake task (can be run with cron on in a DelayedJob worker) like this
task :update_index => :environment do
Sunspot.commit_if_dirty
end
This is far less expensive than doing a commit after every model update, but bear in mind that this introduces the problem of eventual consistency to your index, which is fine for adds but can be nasty for deletes: it will generate orphan entries in your index. This is also a problem with the third way to solve this problem ->
3 - edit your solrconfig.xml file and set the autoCommit
feature with a maxTime
an arbitrary interval between commits (remember to use times in miliseconds). 5 minutes would be nice for most applications, but you should test this yourself.
Hope this helps!