我目前正在構建一個使用gem sunspot
爲我的應用程序提供搜索功能的Rails 3.2應用程序。 sunspot
使用Apache Solr執行全文索引和搜索。如果sunspot-solr不可用,則構建故障安全
def index
@search = Article.search do
fulltext params[:search]
with(:published_at).less_than(Time.zone.now)
paginate :page => params[:page], :per_page => 10
facet(:published_month)
end
@articles = @search.results
respond_to do |format|
format.html # index.html.erb
format.json { render json: @articles }
end
end
現在我的代碼只是在每次有人點擊文章索引頁面然後呈現結果時執行搜索。我擔心的是,solr
出於某種原因,我的應用程序因此死亡。如何在solr
宕機時執行基本的Article.all
此操作的故障安全?
我知道我只能從例外中得到rescue
,但這仍然意味着每個請求都會生成連接嘗試solr
。有沒有辦法來防止這種情況? (例如捕捉異常一次,然後等待5分鐘,應用程序嘗試重新連接到solr
之前)
+1用於解釋高可用性選項。 – aitchnyu 2012-02-04 16:40:02
很好解釋和幫助了很多!謝謝。 – halfdan 2012-02-06 10:49:16
我剛剛叉'太陽黑子',以允許設置超時,但後來我發現這個提交:https://github.com/sunspot/sunspot/commit/abc3b472c917cea50e6e5ace813a4d13ad1ac08a 所以它已經實施。太好了! – halfdan 2012-02-06 12:30:55