diff --git a/setup.py b/setup.py index 9199399..b450100 100755 --- a/setup.py +++ b/setup.py @@ -50,7 +50,7 @@ except: setuptools.setup( name='warcprox', - version='2.1b1.dev88', + version='2.1b1.dev89', description='WARC writing MITM HTTP/S proxy', url='https://github.com/internetarchive/warcprox', author='Noah Levitt', diff --git a/warcprox/stats.py b/warcprox/stats.py index 6332cb9..6e0afdd 100644 --- a/warcprox/stats.py +++ b/warcprox/stats.py @@ -232,25 +232,28 @@ class RethinkStatsDb(StatsDb): }))) def _update_batch(self): - with self._batch_lock: - if len(self._batch) > 0: - # XXX can all the buckets be done in one query? - for bucket in self._batch: - result = self._bucket_batch_update_reql(bucket).run() - if (not result["inserted"] and not result["replaced"] - or sorted(result.values()) != [0,0,0,0,0,1]): - raise Exception( - "unexpected result %s updating stats %s" % ( - result, self._batch[bucket])) - self._batch = {} - - if not self._stop.is_set(): - self._timer = threading.Timer(2.0, self._update_batch) - self._timer.name = "RethinkStats-batch-update-timer-%s" % ( - datetime.datetime.utcnow().isoformat()) - self._timer.start() - else: - self.logger.info("finished") + try: + with self._batch_lock: + if len(self._batch) > 0: + # XXX can all the buckets be done in one query? + for bucket in self._batch: + result = self._bucket_batch_update_reql(bucket).run() + if (not result["inserted"] and not result["replaced"] + or sorted(result.values()) != [0,0,0,0,0,1]): + raise Exception( + "unexpected result %s updating stats %s" % ( + result, self._batch[bucket])) + self._batch = {} + except Exception as e: + self.logger.error("problem updating stats", exc_info=True) + finally: + if not self._stop.is_set(): + self._timer = threading.Timer(2.0, self._update_batch) + self._timer.name = "RethinkStats-batch-update-timer-%s" % ( + datetime.datetime.utcnow().isoformat()) + self._timer.start() + else: + self.logger.info("finished") def _ensure_db_table(self): dbs = self.rr.db_list().run()