Make sure builders close the db handle when no work comes in and make the metrics transaction smaller in scope
This commit is contained in:
parent
fb2470615b
commit
c06f57a6e7
2 changed files with 8 additions and 6 deletions
|
@ -41,20 +41,20 @@ class WorkQueue(object):
|
||||||
return '%s%%' % self._canonical_name([self._queue_name] + self._canonical_name_match_list)
|
return '%s%%' % self._canonical_name([self._queue_name] + self._canonical_name_match_list)
|
||||||
|
|
||||||
def update_metrics(self):
|
def update_metrics(self):
|
||||||
with self._transaction_factory(db):
|
if self._reporter is None:
|
||||||
if self._reporter is None:
|
return
|
||||||
return
|
|
||||||
|
|
||||||
|
with self._transaction_factory(db):
|
||||||
now = datetime.utcnow()
|
now = datetime.utcnow()
|
||||||
name_match_query = self._name_match_query()
|
name_match_query = self._name_match_query()
|
||||||
|
|
||||||
running_query = self._running_jobs(now, name_match_query)
|
running_query = self._running_jobs(now, name_match_query)
|
||||||
running_count =running_query.distinct().count()
|
running_count = running_query.distinct().count()
|
||||||
|
|
||||||
avialable_query = self._available_jobs(now, name_match_query, running_query)
|
avialable_query = self._available_jobs(now, name_match_query, running_query)
|
||||||
available_count = avialable_query.select(QueueItem.queue_name).distinct().count()
|
available_count = avialable_query.select(QueueItem.queue_name).distinct().count()
|
||||||
|
|
||||||
self._reporter(self._currently_processing, running_count, running_count + available_count)
|
self._reporter(self._currently_processing, running_count, running_count + available_count)
|
||||||
|
|
||||||
def put(self, canonical_name_list, message, available_after=0, retries_remaining=5):
|
def put(self, canonical_name_list, message, available_after=0, retries_remaining=5):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -122,6 +122,8 @@ class Worker(object):
|
||||||
with self._current_item_lock:
|
with self._current_item_lock:
|
||||||
current_queue_item = self.current_queue_item
|
current_queue_item = self.current_queue_item
|
||||||
if current_queue_item is None:
|
if current_queue_item is None:
|
||||||
|
# Close the db handle.
|
||||||
|
self._close_db_handle()
|
||||||
break
|
break
|
||||||
|
|
||||||
logger.debug('Queue gave us some work: %s', current_queue_item.body)
|
logger.debug('Queue gave us some work: %s', current_queue_item.body)
|
||||||
|
@ -143,7 +145,7 @@ class Worker(object):
|
||||||
self._stop.set()
|
self._stop.set()
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
# Close the db handle periodically
|
# Close the db handle.
|
||||||
self._close_db_handle()
|
self._close_db_handle()
|
||||||
|
|
||||||
if not self._stop.is_set():
|
if not self._stop.is_set():
|
||||||
|
|
Reference in a new issue