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):
|
||||
|
|
Reference in a new issue