Skip to content

Commit

Permalink
Better error handling of initialization
Browse files Browse the repository at this point in the history
If initialization fails, kill the process rather than hanging out unable
to process queries.
  • Loading branch information
geoffdavis committed Jun 22, 2015
1 parent 585d8d8 commit 53a6bd1
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions bin/export/dbwfserver/resource.py
Expand Up @@ -51,6 +51,9 @@ def __init__(self,config,dbname):
self.logger.info(' Loading! ')
self.logger.info('########################')

self.init_finished=False
self.init_failure=False

self.config = config
self.dbname = dbname
self.loading_stations = True
Expand Down Expand Up @@ -109,7 +112,18 @@ def __init__(self,config,dbname):
'No valid databases to work with! -v or -V for more info')
return False

deferToThread(self._init_in_thread)
d=deferToThread(self._init_in_thread)
d.addCallback(self._init_finished)
d.addErrback(self._init_failed)

def _init_finished(self,d):
self.init_finished=True

def _init_failed(self,failure):
self.init_failure=True
self.logger.critical('An error occurred during initialization: ' +
str(failure))
sys.exit(twisted.internet.reactor.stop())

def _init_in_thread(self):

Expand Down Expand Up @@ -695,11 +709,13 @@ def get_data(self,query):
else:
page = ""

run = "dbwfserver_extract %s %s %s %s %s %s %s %s %s -n %s -m %s %s %s %s 2>&1" % ( regex, coverage, filter, page, calibrate, precision, realtime, median, period, self.config.max_traces, self.config.max_points, tempdb, start, end)
run = "dbwfserver_extract %s %s %s %s %s %s %s %s %s -n %s -m %s %s %s %s 2>&1" % (
regex, coverage, filter, page, calibrate, precision, realtime,
median, period, self.config.max_traces, self.config.max_points,
tempdb, start, end
)

self.logger.info("*********")
self.logger.info("QueryParser(): get_data(): Extraction command: [%s]" % run)
self.logger.info("*********")

# Method 1
#master, slave = pty.openpty()
Expand Down

0 comments on commit 53a6bd1

Please sign in to comment.