1
0
mirror of https://github.com/djohnlewis/stackdump synced 2025-04-05 09:13:27 +00:00

Added a check and a nicer message for when the management commands can't connect to solr.

This commit is contained in:
Samuel Lai 2012-08-24 18:48:17 +10:00
parent fb38b02758
commit c240356a7b
2 changed files with 19 additions and 2 deletions
python/src/stackdump/commands

@ -11,6 +11,7 @@ import xml.sax
from datetime import datetime from datetime import datetime
import re import re
import urllib2 import urllib2
import socket
from optparse import OptionParser from optparse import OptionParser
from xml.etree import ElementTree from xml.etree import ElementTree
@ -578,6 +579,13 @@ print('Connected.\n')
# connect to solr # connect to solr
print('Connecting to solr...') print('Connecting to solr...')
solr = Solr(settings.SOLR_URL) solr = Solr(settings.SOLR_URL)
# pysolr doesn't try to connect until a request is made, so we'll make a ping request
try:
solr._send_request('GET', '%s/admin/ping' % solr.path)
except socket.error, e:
print('Failed to connect to solr - error was: %s' % str(e))
print('Aborting.')
sys.exit(2)
print('Connected.\n') print('Connected.\n')
# ensure required tables exist # ensure required tables exist

@ -6,6 +6,7 @@
import os import os
import sys import sys
import socket
from optparse import OptionParser from optparse import OptionParser
from sqlobject import sqlhub, connectionForURI from sqlobject import sqlhub, connectionForURI
@ -44,6 +45,13 @@ def delete_site(site_key):
# connect to solr # connect to solr
print('Connecting to solr...') print('Connecting to solr...')
solr = Solr(settings.SOLR_URL) solr = Solr(settings.SOLR_URL)
# pysolr doesn't try to connect until a request is made, so we'll make a ping request
try:
solr._send_request('GET', '%s/admin/ping' % solr.path)
except socket.error, e:
print('Failed to connect to solr - error was: %s' % str(e))
print('Aborting.')
sys.exit(2)
print('Connected.\n') print('Connected.\n')
site_name = None site_name = None
@ -96,8 +104,9 @@ if __name__ == '__main__':
list_sites() list_sites()
elif cmd_options.delete_site: elif cmd_options.delete_site:
# confirm with the user first # confirm with the user first
answer = raw_input('Are you sure you want to delete %s? ' % cmd_options.delete_site) answer = raw_input('Are you sure you want to delete %s (type "yes" to delete)? ' % cmd_options.delete_site)
if answer.lower() != 'y': if answer.lower() != 'yes':
print 'Aborting on user request.'
sys.exit(1) sys.exit(1)
print '' print ''