Migrate queued metric from processes to threads
This commit is contained in:
parent
07bb9be603
commit
33088f742a
2 changed files with 15 additions and 12 deletions
|
@ -1,7 +1,8 @@
|
|||
import json
|
||||
import logging
|
||||
|
||||
from multiprocessing import Process, Queue
|
||||
from Queue import Queue
|
||||
from threading import Thread
|
||||
from mixpanel import Consumer, Mixpanel
|
||||
|
||||
|
||||
|
@ -17,24 +18,23 @@ class MixpanelQueingConsumer(object):
|
|||
self._mp_queue.put(json.dumps([endpoint, json_message]))
|
||||
|
||||
|
||||
class SendToMixpanel(Process):
|
||||
class SendToMixpanel(Thread):
|
||||
def __init__(self, request_queue):
|
||||
Process.__init__(self)
|
||||
Thread.__init__(self)
|
||||
self.daemon = True
|
||||
|
||||
self._mp_queue = request_queue
|
||||
self._consumer = Consumer()
|
||||
self.daemon = True
|
||||
|
||||
def run(self):
|
||||
logger.debug('Starting mixpanel sender process.')
|
||||
while True:
|
||||
mp_request = self._mp_queue.get()
|
||||
logger.debug('Got queued mixpanel reqeust.')
|
||||
logger.debug('Got queued mixpanel request.')
|
||||
try:
|
||||
self._consumer.send(*json.loads(mp_request))
|
||||
except:
|
||||
# Make sure we don't crash if Mixpanel request fails.
|
||||
pass
|
||||
logger.exception('Failed to send Mixpanel request.')
|
||||
|
||||
|
||||
class FakeMixpanel(object):
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
import logging
|
||||
import boto
|
||||
|
||||
from multiprocessing import Process, Queue
|
||||
from Queue import Queue
|
||||
from threading import Thread
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
@ -35,15 +37,16 @@ class QueueingCloudWatchReporter(object):
|
|||
unit='Percent')
|
||||
|
||||
|
||||
class SendToCloudWatch(Process):
|
||||
class SendToCloudWatch(Thread):
|
||||
""" SendToCloudWatch loops indefinitely and pulls metrics off of a queue then sends it to
|
||||
CloudWatch. """
|
||||
def __init__(self, request_queue, aws_access_key, aws_secret_key):
|
||||
Process.__init__(self)
|
||||
Thread.__init__(self)
|
||||
self.daemon = True
|
||||
|
||||
self._aws_access_key = aws_access_key
|
||||
self._aws_secret_key = aws_secret_key
|
||||
self._put_metrics_queue = request_queue
|
||||
self.daemon = True
|
||||
|
||||
def run(self):
|
||||
logger.debug('Starting CloudWatch sender process.')
|
||||
|
@ -54,7 +57,7 @@ class SendToCloudWatch(Process):
|
|||
try:
|
||||
connection.put_metric_data(*put_metric_args, **kwargs)
|
||||
except:
|
||||
logger.exception('Writing to CloudWatch failed')
|
||||
logger.exception('Failed to write to CloudWatch')
|
||||
|
||||
|
||||
class QueueMetrics(object):
|
||||
|
|
Reference in a new issue