Skip to content

Commit

Permalink
reports module should be optional; be more careful with dictionary
Browse files Browse the repository at this point in the history
use so we don't trip up if it's not configured or partially configured.
  • Loading branch information
metamatt committed Jul 17, 2013
1 parent ba40c25 commit 079cb41
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
16 changes: 8 additions & 8 deletions reports.py
Expand Up @@ -21,24 +21,24 @@ def __init__(self, config, sg_timer, sg_notify):
self.sg_notify = sg_notify

# send startup report
if self.config.startup:
if 'startup' in self.config:
self.sg_notify.notify(self.config.startup, 'Stargate is now running', 'Stargate startup')

# register for shutdown events
sg_signal.add_exit_listener(self.on_exit)
if 'shutdown' in self.config:
sg_signal.add_exit_listener(self.on_exit)

# register for logger.exception
sg_signal.add_exception_listener(self.on_exception)
if 'exception' in self.config:
sg_signal.add_exception_listener(self.on_exception)

# install timers for interval summaries
# TODO...

def on_exception(self):
if self.config.exception:
report = traceback.format_exc();
self.sg_notify.notify(self.config.exception, report, 'Stargate exception report')
report = traceback.format_exc();
self.sg_notify.notify(self.config.exception, report, 'Stargate exception report')

def on_exit(self):
# send shutdown report
if self.config.shutdown:
self.sg_notify.notify(self.config.shutdown, 'Stargate has stopped', 'Stargate shutdown')
self.sg_notify.notify(self.config.shutdown, 'Stargate has stopped', 'Stargate shutdown')
5 changes: 3 additions & 2 deletions sg_house.py
Expand Up @@ -253,8 +253,9 @@ def __init__(self, config):
self.notify = notify.SgNotify(config.notifications) # SgNotify instance
self.persist = persistence.SgPersistence(config.database, # SgPersistence instance
self.events, self.timer)
self.reports = reports.SgReporter(config.reporting, # SgReporter instance
self.timer, self.notify)
if config.get('reporting'):
self.reports = reports.SgReporter(config.reporting, # SgReporter instance
self.timer, self.notify)
self.watchdog = connections.SgWatchdog() # SgWatchdog instance
self.areas_by_name = {} # Map from area name to area object
self.devices_by_id = {} # Map from device id to device object
Expand Down

0 comments on commit 079cb41

Please sign in to comment.