Skip to content

Commit

Permalink
perform a status test when initializing the solr connector
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni committed Feb 17, 2024
1 parent ec99ed8 commit f25886a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/goo/search/solr/solr_admin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ def admin_url
"#{@solr_url}/admin"
end

def solr_alive?
response = @solr.get('admin/ping')
response['status'] == 'OK'
rescue StandardError
return false
end

def fetch_all_collections
collections_url = URI.parse("#{admin_url}/collections?action=LIST")

Expand Down
11 changes: 11 additions & 0 deletions lib/goo/search/solr/solr_connector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ def initialize(solr_url, collection_name)
@solr_url = solr_url
@collection_name = collection_name
@solr = RSolr.connect(url: collection_url)

# Perform a status test and wait up to 30 seconds before raising an error
wait_time = 0
max_wait_time = 30
until solr_alive? || wait_time >= max_wait_time
sleep 1
wait_time += 1
end
raise "Solr instance not reachable within #{max_wait_time} seconds" unless solr_alive?


@custom_schema = false
end

Expand Down

0 comments on commit f25886a

Please sign in to comment.