summaryrefslogtreecommitdiff
path: root/ceilometermiddleware/swift.py
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2016-07-27 15:58:22 +0000
committerGerrit Code Review <review@openstack.org>2016-07-27 15:58:22 +0000
commit809e98c3b24e111c5f28136452a06e9568449519 (patch)
tree9823a40096478db3efb8eeec6229298119b24e78 /ceilometermiddleware/swift.py
parent3aac7144bd4dca2169f05b364996f5753ef2828a (diff)
parente2e48b5d11f2bc2d67093b8a1a47f859afc03e52 (diff)
downloadceilometermiddleware-809e98c3b24e111c5f28136452a06e9568449519.tar.gz
Merge "Fix bug in background sending"
Diffstat (limited to 'ceilometermiddleware/swift.py')
-rw-r--r--ceilometermiddleware/swift.py18
1 files changed, 12 insertions, 6 deletions
diff --git a/ceilometermiddleware/swift.py b/ceilometermiddleware/swift.py
index f9c7605..ed679a7 100644
--- a/ceilometermiddleware/swift.py
+++ b/ceilometermiddleware/swift.py
@@ -150,9 +150,7 @@ class Swift(object):
if Swift.event_queue is None:
send_queue_size = int(conf.get('send_queue_size', 1000))
Swift.event_queue = queue.Queue(send_queue_size)
- Swift.event_sender = SendEventThread(self._notifier)
- Swift.event_sender.start()
- _LOG.debug('Started sender thread')
+ self.start_sender_thread()
Swift.threadLock.release()
def __call__(self, env, start_response):
@@ -280,12 +278,21 @@ class Swift(object):
if self.nonblocking_notify:
try:
Swift.event_queue.put(event, False)
- _LOG.debug('Event %s added to send queue', event.id)
+ if not Swift.event_sender.is_alive():
+ Swift.threadLock.acquire()
+ self.start_sender_thread()
+ Swift.threadLock.release()
+
except queue.Full:
_LOG.warning('Send queue FULL: Event %s not added', event.id)
else:
Swift.send_notification(self._notifier, event)
+ def start_sender_thread(self):
+ Swift.event_sender = SendEventThread(self._notifier)
+ Swift.event_sender.daemon = True
+ Swift.event_sender.start()
+
@staticmethod
def send_notification(notifier, event):
notifier.info({}, 'objectstore.http.request', event.as_dict())
@@ -296,7 +303,6 @@ class SendEventThread(threading.Thread):
def __init__(self, notifier):
super(SendEventThread, self).__init__()
self.notifier = notifier
- self.daemon = True
def run(self):
"""Send events without blocking swift proxy."""
@@ -307,7 +313,7 @@ class SendEventThread(threading.Thread):
_LOG.debug('Got event %s from queue - now send it', event.id)
Swift.send_notification(self.notifier, event)
_LOG.debug('Event %s sent.', event.id)
- except Exception:
+ except BaseException:
_LOG.exception("SendEventThread loop exception")